Skip to content

Commit

Permalink
refactor(projects): init route store in router guide
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Oct 26, 2023
1 parent 0e4cbd9 commit bc056de
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_ROUTER_HISTORY_MODE=hash
VITE_ROUTER_HISTORY_MODE=history
4 changes: 0 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<script setup lang="ts">
import { ConfigProvider } from 'ant-design-vue';
import { useThemeStore } from './store/modules/theme';
import { useRouteStore } from './store/modules/route';
defineOptions({
name: 'App'
});
const theme = useThemeStore();
const { initAuthRoute } = useRouteStore();
initAuthRoute();
</script>

<template>
Expand Down
3 changes: 2 additions & 1 deletion src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const autoRoutes: ElegantRoute[] = [
title: 'home',
i18nKey: 'route.home',
icon: 'mdi:monitor-dashboard',
requiresAuth: true
requiresAuth: true,
constant: true
}
}
]
Expand Down
7 changes: 7 additions & 0 deletions src/router/guard/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Router } from 'vue-router';
import { useRouteStore } from '@/store/modules/route';

/**
* 路由守卫函数
Expand All @@ -8,6 +9,12 @@ export function createRouterGuard(router: Router) {
router.beforeEach(async (_to, _from, next) => {
window.NProgress?.start?.();

const { isInitAuthRoute, initAuthRoute } = useRouteStore();

if (!isInitAuthRoute) {
await initAuthRoute();
}

next();
});
router.afterEach(_to => {
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
} else {
await initDynamicAuthRoute();
}
setIsInitAuthRoute(true);
}

/**
Expand Down

0 comments on commit bc056de

Please sign in to comment.