通过动态路由方式
主要适用于传递一个参数的路由跳转,比如详情页。
//路由配置文件中 配置动态路由
{
path: '/detail/:id',
name: 'Detail',
component: Detail
}
//跳转时页面
var id = 1;
this.$router.push('/detail/' + id)
//跳转后页面获取参数
this.$route.params.id
通过params获取参数
Params只能通过name方式跳转路由。
不配置path参数
第一次获取路由参数能获取到,刷新页面后获取不到路由参数。
//路由配置文件中 不配置path参数
path: "/projFeedbackDetail",
name: "ProjFeedbackDetail",
component: ProjFeedbackDetail
//跳转时页面
this.$router.push({
name: "ProjFeedbackDetail",
params: {
prjId: this.prjId,
cycleId: this.cycleId,
feedbackIdKey: feedbackIdKey
}
});
//跳转后页面
this.prjId = this.$route.params.prjId;
this.cycleId = this.$route.params.cycleId;
this.feedbackIdKey = this.$route.params.feedba