Commit c1178027f0fab2791d02efcd7c52beff5fc7dc25
1 parent
db7254a5
fix: fix homePage affix error
修复当没有通过接口为用户指定首页时,如果默认的首页是一个带有重定向的路由,则可能出现双首页Tab的问题
Showing
2 changed files
with
9 additions
and
5 deletions
src/router/routes/modules/about.ts
src/store/modules/permission.ts
... | ... | @@ -123,15 +123,19 @@ export const usePermissionStore = defineStore({ |
123 | 123 | * */ |
124 | 124 | const patchHomeAffix = (routes: AppRouteRecordRaw[]) => { |
125 | 125 | if (!routes || routes.length === 0) return; |
126 | - const homePath = userStore.getUserInfo.homePath || PageEnum.BASE_HOME; | |
126 | + let homePath: string = userStore.getUserInfo.homePath || PageEnum.BASE_HOME; | |
127 | 127 | function patcher(routes: AppRouteRecordRaw[], parentPath = '') { |
128 | 128 | if (parentPath) parentPath = parentPath + '/'; |
129 | 129 | routes.forEach((route: AppRouteRecordRaw) => { |
130 | - const { path, children } = route; | |
130 | + const { path, children, redirect } = route; | |
131 | 131 | const currentPath = path.startsWith('/') ? path : parentPath + path; |
132 | 132 | if (currentPath === homePath) { |
133 | - route.meta = Object.assign({}, route.meta, { affix: true }); | |
134 | - throw new Error('end'); | |
133 | + if (redirect) { | |
134 | + homePath = route.redirect! as string; | |
135 | + } else { | |
136 | + route.meta = Object.assign({}, route.meta, { affix: true }); | |
137 | + throw new Error('end'); | |
138 | + } | |
135 | 139 | } |
136 | 140 | children && children.length > 0 && patcher(children, currentPath); |
137 | 141 | }); | ... | ... |