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

+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;