RE: RE: Vue.js实战笔记
You are viewing a single comment's thread from:

RE: Vue.js实战笔记

Words
2
Reading
1 min
Listen
Play
7y

参考

//main.js
router.beforeEach(function (to, from, next) {
  if(to.meta.requireAuth){
    // 要去的url只有登陆成功后才能访问
    if (store.state.username) {
      next()
    } else {
      next({name: 'login'})
    }
  }else{
    next()
  }
})

//routers.js
routes: [
    {
      path: '/micro',
      name: 'micro',
      component: Micro,
      meta:{
        requireAuth:true
      }
    },
    {
      path: '/news',
      name: 'news',
      component: News,
      meta:{
        requireAuth:true
      }
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    }
  ],
@lemooljiang: 参考 //main.js | Ecency