发表于: 2020-02-18 22:47:56

1 1372



今天完成的事情:

1.推进任务


明天计划的事情:

1.推进任务


遇到的问题和收获:

1.


export default new Router({
   routes: [
       {
           path: '/selfcenter',
           name: 'selfcenter',
           meta: {
               requireAuth: true // 配置此条,进入页面前判断是否需要登陆
           },
           component: selfcenter
       }
   ]
})


/* eslint-disable no-new */
router.beforeEach((to, from, next) => {
   if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
       if (sessionStorage.getItem('sid')) { // 查询本地存储信息是否已经登陆
           next();
       } else {
           next({
               path: '/login', // 未登录则跳转至login页面
               query: {redirect: to.fullPath} // 登陆成功后回到当前页面,这里传值给login页面,to.fullPath为当前点击的页面
           });
       }
   } else {
       next();
   }
});


回顾一下路由跳转


返回列表 返回列表
评论

    分享到