当要求用户登录才可操作,但是没有登录的时候,路由设置

 1 router.beforeEach((to, from, next) => {
 2   const auth = router.app.$options.store.state.auth
 3 
 4   if (
 5     (auth && to.path.indexOf('/auth/') !== -1) ||
 6     (!auth && to.meta.auth)
 7   ) {
 8     next('/')
 9   } else {
10     next()
11   }
12 })

跳转到首页

posted @ 2018-07-16 13:01  前端极客  阅读(264)  评论(0编辑  收藏  举报