一、
1、路由设置方式
{`在这里插入代码片`
path: '/detail/:id',
name: 'detail',
meta: { keepAlive: true },
component: () => import('../pages/detail/index')
}
2、路由跳转模式
this.$router.push(
{
path: `/detail/1`
}
)
3、获取参数方式
let detailId = this.$route.params.id
注意: params 传参相当于是路由的一部分是必须传的东西,经过验证不传页面会跳转到空白页
该方式刷新页面id 不丢失
二、
1、路由设置方式
{
path: '/detail/:id',
name: 'detail',
meta: { keepAlive: true },
component: () => import('../pages/detail/index')
}
2、路由跳转模式
this.$router.push(
{
name: 'Detail',
params: {
id
}
}
)
3、获取参数方式
let detailId = this.$route.params.id
注意:此方式传参 路由设置方式中的 id 可以传也可以不传,不传刷新页面id 会丢失
该方式刷新页面id 不丢失
三、
1、路由设置方式
{
path: '/detail',
name: 'detail',
meta: { keepAlive: true },
component: () => import('../pages/detail/index')
}
2、路由跳转模式
this.$router.push(
{
path: 'Detail',
query: {
id
}
}
)
3、获取参数方式
let detailId = this.$route.query.id
注意:此方式传参 路由设置方式中的 id 不能写,因为写了就是router 的一部分,这样就会匹配不到, 此方式刷新页面id 不丢失