From 1abf7fdf5f53ffa77a6fa0171a1d2ac21ad96118 Mon Sep 17 00:00:00 2001 From: zuihou <244387066@qq.com> Date: Thu, 23 Sep 2021 12:28:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(route):=20=E5=8A=A8=E6=80=81=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=20component=20=E5=B1=9E=E6=80=A7=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=A5=20/=20=E5=BC=80=E5=A4=B4=E6=88=96=E8=80=85=E4=BB=A5?= =?UTF-8?q?=20.vue=20=E5=92=8C=20.tsx=20=E7=BB=93=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/helper/routeHelper.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/router/helper/routeHelper.ts b/src/router/helper/routeHelper.ts index 8fa9e75a..d1ff3bb1 100644 --- a/src/router/helper/routeHelper.ts +++ b/src/router/helper/routeHelper.ts @@ -46,10 +46,12 @@ function dynamicImport( ) { const keys = Object.keys(dynamicViewsModules); const matchKeys = keys.filter((key) => { - let k = key.replace('../../views', ''); - const lastIndex = k.lastIndexOf('.'); - k = k.substring(0, lastIndex); - return k === component; + const k = key.replace('../../views', ''); + const startFlag = component.startsWith('/'); + const endFlag = component.endsWith('.vue') || component.endsWith('.tsx'); + const startIndex = startFlag ? 0 : 1; + const lastIndex = endFlag ? k.length : k.lastIndexOf('.'); + return k.substring(startIndex, lastIndex) === component; }); if (matchKeys?.length === 1) { const matchKey = matchKeys[0]; @@ -60,7 +62,7 @@ function dynamicImport( ); return; } else { - warn('在src/views/下找不到`' + component + '.vue` 或 `' + component + '.TSX`, 请自行创建!'); + warn('在src/views/下找不到`' + component + '.vue` 或 `' + component + '.tsx`, 请自行创建!'); return EXCEPTION_COMPONENT; } } @@ -82,6 +84,8 @@ export function transformObjToRoute(routeList: AppRouteModul meta.affix = false; route.meta = meta; } + } else { + warn('请正确配置路由:' + route?.name + '的component属性'); } route.children && asyncImportRoute(route.children); });