route /login managed through vue router
This commit is contained in:
parent
5b3549068b
commit
de52c5e6be
4 changed files with 41 additions and 32 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import { createWebHistory, createRouter } from "vue-router";
|
||||
import routes from "./routes";
|
||||
import { useApiStore } from "../stores/api";
|
||||
import { usePageStore } from "../stores/page";
|
||||
import { useUserStore } from "../stores/user";
|
||||
import { getActivePinia } from "pinia";
|
||||
import { createWebHistory, createRouter } from 'vue-router';
|
||||
import routes from './routes';
|
||||
import { useApiStore } from '../stores/api';
|
||||
import { usePageStore } from '../stores/page';
|
||||
import { useUserStore } from '../stores/user';
|
||||
import { getActivePinia } from 'pinia';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
|
|
@ -12,10 +12,14 @@ const router = createRouter({
|
|||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const pinia = getActivePinia();
|
||||
const api = useApiStore(pinia);
|
||||
const pageStore = usePageStore(pinia);
|
||||
const userStore = useUserStore(pinia);
|
||||
|
||||
if (to.path === '/login') next();
|
||||
|
||||
if (!userStore.user) next('/login');
|
||||
|
||||
const api = useApiStore(pinia);
|
||||
try {
|
||||
const res = await api.fetchData(to.path);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ const routes = [
|
|||
component: Home,
|
||||
},
|
||||
{
|
||||
name: 'Login',
|
||||
path: '/login',
|
||||
component: Login,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue