Skip to content

Commit

Permalink
feat(projects): add reset routes
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 10, 2023
1 parent 3f22efa commit 76400a8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
const authStore = useAuthStore();
const tabStore = useTabStore();
const { bool: isInitAuthRoute, setBool: setIsInitAuthRoute } = useBoolean();
const removeRouteFns: (() => void)[] = [];

/**
* auth route mode
Expand Down Expand Up @@ -135,6 +136,16 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
const routeStore = useRouteStore();

routeStore.$reset();

resetVueRoutes();
}

/**
* reset vue routes
*/
function resetVueRoutes() {
removeRouteFns.forEach(fn => fn());
removeRouteFns.length = 0;
}

/**
Expand Down Expand Up @@ -198,10 +209,19 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
*/
function addRoutesToVueRouter(routes: RouteRecordRaw[]) {
routes.forEach(route => {
router.addRoute(route);
const removeFn = router.addRoute(route);
addRemoveRouteFn(removeFn);
});
}

/**
* add remove route fn
* @param fn
*/
function addRemoveRouteFn(fn: () => void) {
removeRouteFns.push(fn);
}

/**
* update root route redirect when auth route mode is dynamic
* @param redirectKey redirect route key
Expand Down

0 comments on commit 76400a8

Please sign in to comment.