@H_403_0@除了使用
@H_403_0@
router.push(location)
@H_403_0@想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。 @H_403_0@当你点击// 对象
this.$router.push({path: '/login?url=' + this.$route.path});
@H_403_0@this.$router.push({path: '/login?url=' + this.$route.path});
// 命名的路由
router.push({ name: 'user',params: { userId: 123 }})
// 带查询参数,变成/backend/order?selected=2
this.$router.push({path: '/backend/order',query: {selected: "2"}});
// 设置查询参数
this.$http.post('v1/user/select-stage',{stage: stage})
.then(({data: {code,content}}) => {
if (code === 0) {
// 对象
this.$router.push({path: '/home'});
}else if(code === 10){
// 带查询参数,变成/login?stage=stage
this.$router.push({path: '/login',query:{stage: stage}});
}
});
// 设计查询参数对象
let queryData = {};
if (this.$route.query.stage) {
queryData.stage = this.$route.query.stage;
}
if (this.$route.query.url) {
queryData.url = this.$route.query.url;
}
this.$router.push({path: '/my/profile',query: queryData});
replace
@H_403_0@类型: boolean @H_403_0@默认值: false @H_403_0@设置 replace 属性的话,当点击时,会调用 router.replace() 而不是 router.push(),于是导航后不会留下 history 记录。即使点击返回按钮也不会回到这个页面。 @H_403_0@//加上replace: true后,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。
// 编程式:
router.replace(...)
@H_403_0@