vue+axios 루트 차단

1201 단어 vue
const router = new Router({
  routes: [
    {path: '/', redirect: '/login'},
    {path: '/login', name: 'login', component: login},
    {
      path: '/manage', name: 'manage', component: manage,

      children: [
        {path: '/manage/', redirect: '/manage/index'},
        {path: '/manage/index', name: 'index', component: Index, meta: {requireAuth: true}},
        {path: '/manage/travelOrder', name: 'travelOrder', component: travelOrder, meta: {requireAuth: true}}
      ]
    },

  ]
});
    
// meta: {
//   requireAuth: true,  //      ,              
// },
router.beforeEach((to, from, next) => {

  if (to.meta.requireAuth) {  //              
   // setTimeout(()=>{
      if (localStorage.getItem('token')) {  // localStorage     token    
        next();
      }
      else {
        Message.error('     ');
        next({
          path: '/login',
          query: {redirect: to.fullPath}  //       path    ,           
        })
      }
   // },10000)
  }
  else {
    next();
  }
})

좋은 웹페이지 즐겨찾기