Skip to content

Commit

Permalink
feat: suppor *
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Aug 3, 2022
1 parent 616672c commit 2bb753d
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/transformRoute/transformRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ function formatter(
if (!item) return false;
if (notNullArray(item[childrenPropsName])) return true;
if (notNullArray(item.children)) return true;
if (item.path === '*') return false;
if (item.path === '/*') return false;

if (item.path) return true;
if (item.layout) return true;
// 重定向
Expand All @@ -194,6 +193,12 @@ function formatter(
// eslint-disable-next-line no-param-reassign
delete item.name;
}
if (item.path === '*') {
item.path = '.';
}
if (item.path === '/*') {
item.path = '.';
}
return item;
})

Expand Down
33 changes: 33 additions & 0 deletions test/__snapshots__/getFlatMenus.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ Object {
"routes": undefined,
"unaccessible": false,
},
Object {
"access": "canAdmin",
"key": "/admin/.",
"locale": "menu.admin.404",
"name": "menu.admin.404",
"path": "/admin/.",
"pro_layout_parentKeys": Array [
"/admin",
],
"routes": undefined,
},
],
"key": "/admin",
"locale": "menu.admin",
Expand All @@ -38,7 +49,29 @@ Object {
"routes": undefined,
"unaccessible": false,
},
Object {
"access": "canAdmin",
"key": "/admin/.",
"locale": "menu.admin.404",
"name": "menu.admin.404",
"path": "/admin/.",
"pro_layout_parentKeys": Array [
"/admin",
],
"routes": undefined,
},
],
},
"/admin/.": Object {
"access": "canAdmin",
"key": "/admin/.",
"locale": "menu.admin.404",
"name": "menu.admin.404",
"path": "/admin/.",
"pro_layout_parentKeys": Array [
"/admin",
],
"routes": undefined,
},
"/admin/sub-page": Object {
"access": "canAdmin",
Expand Down
52 changes: 52 additions & 0 deletions test/__snapshots__/transformRoute.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ Array [
"path": "/",
"pro_layout_parentKeys": Array [],
},
Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
]
`;

Expand Down Expand Up @@ -312,6 +319,13 @@ Map {
"path": "/",
"pro_layout_parentKeys": Array [],
},
"/." => Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
}
`;

Expand Down Expand Up @@ -3193,6 +3207,16 @@ Map {
},
],
},
"/." => Object {
"exact": false,
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [
"qixian",
],
"redirect": "./Exception/404",
},
}
`;

Expand Down Expand Up @@ -3462,6 +3486,13 @@ Map {
"path": "/",
"pro_layout_parentKeys": Array [],
},
"/." => Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
}
`;

Expand Down Expand Up @@ -3743,6 +3774,13 @@ Map {
"path": "/",
"pro_layout_parentKeys": Array [],
},
"/." => Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
}
`;

Expand Down Expand Up @@ -3888,6 +3926,13 @@ Array [
"path": "/",
"pro_layout_parentKeys": Array [],
},
Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
]
`;

Expand Down Expand Up @@ -4058,5 +4103,12 @@ Map {
"path": "/",
"pro_layout_parentKeys": Array [],
},
"/." => Object {
"component": "./404",
"key": "/.",
"locale": false,
"path": "/.",
"pro_layout_parentKeys": Array [],
},
}
`;
2 changes: 1 addition & 1 deletion test/getFlatMenus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const { menuData } = transformRoute(routes, true, ({ id }) => {
describe('getFlatMenus', () => {
it('normal', () => {
const flatMenus = getFlatMenus(menuData);
expect(Object.keys(flatMenus).length).toEqual(5);
expect(Object.keys(flatMenus).length).toEqual(6);
expect(flatMenus['/list'].name).toEqual('查询表格');
expect(flatMenus).toMatchSnapshot();
});
Expand Down

0 comments on commit 2bb753d

Please sign in to comment.