Commit fde0c879 authored by 汪晓凯's avatar 汪晓凯

添加路由守卫

parent dc1c2368
...@@ -3,7 +3,7 @@ import Router from 'vue-router' ...@@ -3,7 +3,7 @@ import Router from 'vue-router'
Vue.use(Router) Vue.use(Router)
export default new Router({ const router = new Router({
routes: [ routes: [
{ {
path: '/', path: '/',
...@@ -57,3 +57,15 @@ export default new Router({ ...@@ -57,3 +57,15 @@ export default new Router({
}, },
] ]
}) })
//配置路由守卫
router.beforeEach((to, from, next) => {//在每次涂油跳转的时候都触发一次
if (to.matched.length === 0) { // 如果未匹配到路由
from.name ? next({ name: from.name }) : next('/'); // 如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
} else {
next(); // 如果匹配到正确跳转
}
});
export default router
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment