在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue路由params如果沒有,如何批量跳轉(zhuǎn)404?

vue路由params如果沒有,如何批量跳轉(zhuǎn)404?

/goods/:id
/user/:id
如果id 不存在那怎么跳轉(zhuǎn)到404或者其他頁面?
正常鏈接進(jìn)來是不會(huì),萬一改url上的id 結(jié)果沒有這個(gè)id呢?

我在created()的時(shí)候會(huì)去請(qǐng)求詳情,可以在這里判斷 如果沒有就跳轉(zhuǎn),
但是我好多這樣的路由,難道每個(gè)都要判斷??

回答
編輯回答
影魅

1.參考權(quán)限token校驗(yàn)
router.beforeEach((to, from, next) => {

   if (to.meta.requireAuth) {
       if (store.state.token) {
            next();
        }
    }else {
        next({
            path: '/login',
            query: {redirect:to.fullPath}  
        })
    }
}
else {
    next();
}

})

2017年12月17日 06:14
編輯回答
做不到

const router = new VueRouter({ ... })

router.beforeEach((to, from, next) => {
// ...
})

2018年9月12日 14:02
編輯回答
葬憶

使用beforeRouteUpdate ,傳送門:https://router.vuejs.org/zh-c...

const User = {
  template: '...',
  beforeRouteUpdate (to, from, next) {
    // react to route changes...
    // don't forget to call next()
  }
}
2017年11月29日 14:09