Skip to content

Commit

Permalink
fix: utils nofind
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Apr 18, 2022
1 parent dd52a54 commit 5f93bc0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
3 changes: 1 addition & 2 deletions packages/umi-presets-alita/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
"@alitajs/plugin-mobile5": "2.8.35",
"@alitajs/router": "2.8.15",
"@alitajs/routes": "2.8.35",
"@alitajs/utils": "2.8.35",
"@umijs/plugin-antd": "0.15.0",
"@umijs/plugin-esbuild": "1.3.1",
"@umijs/plugin-helmet": "1.1.3",
"@umijs/plugin-request": "2.5.2"
}
}
}
30 changes: 29 additions & 1 deletion packages/umi-presets-alita/src/plugins/features/mainPath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import { IApi } from 'umi';
import { resetMainPath } from '@alitajs/utils';

function resetMainPath(routes: any[], mainPath: string) {
let newPath = mainPath;
// 把用户输入/abc/ 转成 /abc
if (newPath !== '/' && newPath.slice(-1) === '/') {
newPath = newPath.slice(0, -1);
}
// 把用户输入abc 转成 /abc
if (newPath !== '/' && newPath.slice(0, 1) !== '/') {
newPath = `/${newPath}`;
}
return routes.map((element) => {
if (element.isResetMainEdit) {
return element;
}
if (element.path === '/' && !element.routes) {
element.path = '/index';
element.isResetMainEdit = true;
}
if (element.path === newPath) {
element.path = '/';
element.isResetMainEdit = true;
}
if (Array.isArray(element.routes)) {
element.routes = resetMainPath(element.routes, mainPath);
}
return element;
});
}

export default (api: IApi) => {
api.describe({
Expand Down

0 comments on commit 5f93bc0

Please sign in to comment.