路由守卫

  const  router =  new  Router({
    routes: [
      {
      path: '/',
      component: landing
    },
    {
      path: '/home',
      component: home,
      children:[
        {
          path:'/chat',
          component:chat
        },
        {
          path:'/uploading',
          component:uploading
        },
        {
          path:'/list',
          component:list
        }
      ],
      meta: {
        isnologin: false,
      }
    },
    {
      path: '/register',
      component: register
    }
]
  })
  router.beforeEach((to, from, next) => {
    if(to.meta.isnologin == false) {
    var mylogin = cookies.get('token')
    if(!mylogin) {
      if(to.path == "/" || to.path == "/register") {
        next();
        } else {
          next("/")

    }
  } else {
    next();
  }
} else {
  next();
}
})

export default router;

你可能感兴趣的:(路由守卫)