diff --git a/src/router/index.js b/src/router/index.js index 0c11af0..14e6c55 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -7,6 +7,9 @@ const routes = [ path: '/', name: 'home', component: HomeView, + meta: { + requireAuth: true, + }, }, { path: '/login', @@ -25,4 +28,10 @@ const router = createRouter({ routes, }); +router.beforeEach(async (to,from,next) => { + const isAuthenticate = sessionStorage.getItem('access_token'); + if (to.meta.requireAuth && !isAuthenticate || isAuthenticate === 'undefined' || isAuthenticate === 'null') { + next({name: 'login'}); + } else next(); + }) export default router;