diff --git a/src/router/index.js b/src/router/index.js index dff2277..edf2ec3 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -22,5 +22,14 @@ const routes = [ const router = new VueRouter({ routes }) - +router.beforeEach((to, from, next) => { + if (to.path === '/login') { + return next() + } + const token = sessionStorage.getItem('token') + if (!token) { + return next('/login') + } + next() +}) export default router