add login redirect
This commit is contained in:
1 parent
a94be71c98
commit
2a5a5c601c
12 files changed
+113
-15
No files matched your search
+1
-1
@@ -10,7 +10,7 @@ export default {
|
||||
children: [
|
||||
{
|
||||
path: 'login',
|
||||
name: 'auth-login',
|
||||
name: 'login',
|
||||
meta: {
|
||||
title: t('common.nav.article')
|
||||
},
|
||||
|
||||
@@ -4,7 +4,8 @@ export default {
|
||||
path: '/content',
|
||||
name: 'content',
|
||||
meta: {
|
||||
title: t('common.nav.content')
|
||||
title: t('common.nav.content'),
|
||||
auth: true
|
||||
},
|
||||
component: () => import('@/layouts/Content.vue'),
|
||||
children: [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
|
||||
import content from './content';
|
||||
import auth from './auth';
|
||||
import store from '@/store';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
@@ -19,4 +20,20 @@ const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.matched.some((record) => record.meta.auth)) {
|
||||
if (!store.getters.authenticated) {
|
||||
next({
|
||||
name: 'login',
|
||||
query: { redirect: to.fullPath }
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in new issue
Block a user