vue路由可以强制携带参数吗?

定义了路由规则
`{

path: '/app_article/:id',
name: 'App_article',
component: App_article

}
`

我想让用户进入app_article页面时,必须强制携带参数。如果发现没有ID参数,自动让返回上一页

阅读 2.1k
3 个回答
{
    path: '/app_article/:id',
    name: 'App_article',
    component: App_article,
    beforeEnter: (to, from, next) => {
        // 处理ID
        ...
    } 
}
{
    path: '/app_article/:id',
    name: 'App_article',
    component: App_article,
    beforeEnter: (to, from, next) => {
        let params = to.params;
        if (params.id !== undefined) {
            next(true)
        } else {
            next(false);
        }
    } 
}
新手上路,请多包涵

在页面内处理的方式
created() {

if (!this.$route.query.id) {
  this.$router.go(-1)
  return
}

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题