Commit 452b2599f4dca616a9699781783eb2480d0569e4
1 parent
7028e003
fix(route): 获取 LAYOUT 或 IFRAME 忽略大小写。 并且在通过component找不到页面时打印警告,并返回404页面
Showing
1 changed file
with
6 additions
and
4 deletions
src/router/helper/routeHelper.ts
1 | import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types'; | 1 | import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types'; |
2 | import type { Router, RouteRecordNormalized } from 'vue-router'; | 2 | import type { Router, RouteRecordNormalized } from 'vue-router'; |
3 | 3 | ||
4 | -import { getParentLayout, LAYOUT } from '/@/router/constant'; | 4 | +import { getParentLayout, LAYOUT, EXCEPTION_COMPONENT } from '/@/router/constant'; |
5 | import { cloneDeep, omit } from 'lodash-es'; | 5 | import { cloneDeep, omit } from 'lodash-es'; |
6 | import { warn } from '/@/utils/log'; | 6 | import { warn } from '/@/utils/log'; |
7 | import { createRouter, createWebHashHistory } from 'vue-router'; | 7 | import { createRouter, createWebHashHistory } from 'vue-router'; |
@@ -27,7 +27,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { | @@ -27,7 +27,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { | ||
27 | const { component, name } = item; | 27 | const { component, name } = item; |
28 | const { children } = item; | 28 | const { children } = item; |
29 | if (component) { | 29 | if (component) { |
30 | - const layoutFound = LayoutMap.get(component as string); | 30 | + const layoutFound = LayoutMap.get(component.toUpperCase()); |
31 | if (layoutFound) { | 31 | if (layoutFound) { |
32 | item.component = layoutFound; | 32 | item.component = layoutFound; |
33 | } else { | 33 | } else { |
@@ -54,12 +54,14 @@ function dynamicImport( | @@ -54,12 +54,14 @@ function dynamicImport( | ||
54 | if (matchKeys?.length === 1) { | 54 | if (matchKeys?.length === 1) { |
55 | const matchKey = matchKeys[0]; | 55 | const matchKey = matchKeys[0]; |
56 | return dynamicViewsModules[matchKey]; | 56 | return dynamicViewsModules[matchKey]; |
57 | - } | ||
58 | - if (matchKeys?.length > 1) { | 57 | + } else if (matchKeys?.length > 1) { |
59 | warn( | 58 | warn( |
60 | 'Please do not create `.vue` and `.TSX` files with the same file name in the same hierarchical directory under the views folder. This will cause dynamic introduction failure', | 59 | 'Please do not create `.vue` and `.TSX` files with the same file name in the same hierarchical directory under the views folder. This will cause dynamic introduction failure', |
61 | ); | 60 | ); |
62 | return; | 61 | return; |
62 | + } else { | ||
63 | + warn('在src/views/下找不到`' + component + '.vue` 或 `' + component + '.TSX`, 请自行创建!'); | ||
64 | + return EXCEPTION_COMPONENT; | ||
63 | } | 65 | } |
64 | } | 66 | } |
65 | 67 |