Commit 452b2599f4dca616a9699781783eb2480d0569e4

Authored by zuihou
1 parent 7028e003

fix(route): 获取 LAYOUT 或 IFRAME 忽略大小写。 并且在通过component找不到页面时打印警告,并返回404页面

src/router/helper/routeHelper.ts
1 1 import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types';
2 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 5 import { cloneDeep, omit } from 'lodash-es';
6 6 import { warn } from '/@/utils/log';
7 7 import { createRouter, createWebHashHistory } from 'vue-router';
... ... @@ -27,7 +27,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
27 27 const { component, name } = item;
28 28 const { children } = item;
29 29 if (component) {
30   - const layoutFound = LayoutMap.get(component as string);
  30 + const layoutFound = LayoutMap.get(component.toUpperCase());
31 31 if (layoutFound) {
32 32 item.component = layoutFound;
33 33 } else {
... ... @@ -54,12 +54,14 @@ function dynamicImport(
54 54 if (matchKeys?.length === 1) {
55 55 const matchKey = matchKeys[0];
56 56 return dynamicViewsModules[matchKey];
57   - }
58   - if (matchKeys?.length > 1) {
  57 + } else if (matchKeys?.length > 1) {
59 58 warn(
60 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 61 return;
  62 + } else {
  63 + warn('在src/views/下找不到`' + component + '.vue` 或 `' + component + '.TSX`, 请自行创建!');
  64 + return EXCEPTION_COMPONENT;
63 65 }
64 66 }
65 67  
... ...