refactor(@vben/access): 重构路由的重定向逻辑
@vben-core/shared @vben/playground @vben/backend-mock @vben/web-antd @vben/web-antdv-next @vben/web-ele @vben/naive @vben/tdesign
This commit is contained in:
@@ -115,7 +115,7 @@ async function generateRoutes(
|
||||
* 1. 对未添加redirect的路由添加redirect
|
||||
* 2. 将懒加载的组件名称修改为当前路由的名称(如果启用了keep-alive的话)
|
||||
*/
|
||||
resultRoutes = mapTree(resultRoutes, (route) => {
|
||||
resultRoutes = mapTree(resultRoutes, (route, parent) => {
|
||||
// 重新包装component,使用与路由名称相同的name以支持keep-alive的条件缓存。
|
||||
if (
|
||||
route.meta?.keepAlive &&
|
||||
@@ -144,12 +144,19 @@ async function generateRoutes(
|
||||
}
|
||||
const firstChild = route.children[0];
|
||||
|
||||
// 如果子路由不是以/开头,则直接返回,这种情况需要计算全部父级的path才能得出正确的path,这里不做处理
|
||||
if (!firstChild?.path || !firstChild.path.startsWith('/')) {
|
||||
if (!firstChild?.path || firstChild.path.startsWith('/')) {
|
||||
return route;
|
||||
}
|
||||
|
||||
route.redirect = firstChild.path;
|
||||
if (parent && parent.redirect) {
|
||||
const parentSplit = (parent.redirect as string).split('/');
|
||||
parentSplit.splice(-1, 2, route.path, firstChild.path);
|
||||
const redirectPath = parentSplit.join('/');
|
||||
route.redirect = redirectPath;
|
||||
} else {
|
||||
route.redirect = `${route.path}/${firstChild.path}`;
|
||||
}
|
||||
|
||||
return route;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user