로그인 화면
This commit is contained in:
1 parent
6adcb5b43d
commit
f551671394
13 files changed
+152
-30
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import VueRouter from "vue-router";
|
||||
import routes from "./routes";
|
||||
import { isAuthenticated, safeDestination } from '@/auth';
|
||||
|
||||
// configure router
|
||||
const router = new VueRouter({
|
||||
@@ -14,4 +15,12 @@ const router = new VueRouter({
|
||||
}
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.matched.some(record => record.meta.requiresAuth) && !isAuthenticated()) {
|
||||
next({ path: '/login', query: { redirect: to.fullPath }, replace: true });
|
||||
} else if (to.name === 'login' && isAuthenticated()) {
|
||||
next({ path: safeDestination(to.query.redirect), replace: true });
|
||||
} else next();
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,6 +1,8 @@
|
||||
import Dashboard from '@/pages/Dashboard.vue';
|
||||
import Login from '@/pages/Login.vue';
|
||||
export default [
|
||||
{ path: '/', redirect: '/dashboard' },
|
||||
{ path: '/dashboard', name: 'dashboard', component: Dashboard },
|
||||
{ path: '/login', name: 'login', component: Login },
|
||||
{ path: '/dashboard', name: 'dashboard', component: Dashboard, meta: { requiresAuth: true } },
|
||||
{ path: '*', redirect: '/dashboard' }
|
||||
];
|
||||
Reference in new issue
Block a user