add login redirect

This commit is contained in:
AceDataCloud committed 2021-09-11 01:59:39 +08:00
1 parent a94be71c98
commit 2a5a5c601c
12 files changed
+113 -15

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ export default {
children: [
{
path: 'login',
name: 'auth-login',
name: 'login',
meta: {
title: t('common.nav.article')
},
+2 -1
View File
@@ -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: [
+17
View File
@@ -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;