From 7ef10557d2151ed3a0eb36800ea6867a56082965 Mon Sep 17 00:00:00 2001 From: harrywan <445436867@qq.com> Date: Fri, 8 Jul 2022 10:19:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=90=8D=E5=B8=A6@=E8=BD=AC=E5=8C=96=E6=88=90=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=B7=AF=E7=94=B1=20(#137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/misc/route/index.js | 23 ++++++++----------- packages/fes-template/src/pages/@id/add.vue | 0 2 files changed, 9 insertions(+), 14 deletions(-) create mode 100644 packages/fes-template/src/pages/@id/add.vue diff --git a/packages/fes-preset-built-in/src/plugins/misc/route/index.js b/packages/fes-preset-built-in/src/plugins/misc/route/index.js index f963cb00..a47eacb7 100644 --- a/packages/fes-preset-built-in/src/plugins/misc/route/index.js +++ b/packages/fes-preset-built-in/src/plugins/misc/route/index.js @@ -50,14 +50,9 @@ const getRouteName = function (parentRoutePath, fileName) { .replace(/\*/g, 'FUZZYMATCH'); }; -const getComponentPath = function (parentRoutePath, fileName, config) { - const pagesName = config.singular ? 'page' : 'pages'; - return posix.join(`@/${pagesName}/`, parentRoutePath, fileName); -}; - -const getRoutePath = function (parentRoutePath, fileName) { +const getRoutePath = function (parentRoutePath, fileName, isFile = true) { // /index.vue -> / - if (fileName === 'index') { + if (isFile && fileName === 'index') { fileName = ''; } // /@id.vue -> /:id @@ -87,7 +82,7 @@ function getRouteMeta(content) { let cacheGenRoutes = {}; // TODO 约定 layout 目录作为布局文件夹, -const genRoutes = function (parentRoutes, path, parentRoutePath, config) { +const genRoutes = function (parentRoutes, path, parentRoutePath) { const dirList = readdirSync(path); const hasLayout = checkHasLayout(path); const layoutRoute = { @@ -113,7 +108,7 @@ const genRoutes = function (parentRoutes, path, parentRoutePath, config) { // 路由名称 const routeName = getRouteName(parentRoutePath, fileName); - const componentPath = getComponentPath(parentRoutePath, fileName, config); + const componentPath = posix.join(path, item); let content = readFileSync(component, 'utf-8'); let routeMeta = {}; @@ -153,12 +148,12 @@ const genRoutes = function (parentRoutes, path, parentRoutePath, config) { dirList.forEach((item) => { if (isProcessDirectory(path, item)) { // 文件或者目录的绝对路径 - const component = join(path, item); - const nextParentRouteUrl = posix.join(parentRoutePath, item); + const nextPath = join(path, item); + const nextParentRouteUrl = getRoutePath(parentRoutePath, item, false); if (hasLayout) { - genRoutes(layoutRoute.children, component, nextParentRouteUrl, config); + genRoutes(layoutRoute.children, nextPath, nextParentRouteUrl); } else { - genRoutes(parentRoutes, component, nextParentRouteUrl, config); + genRoutes(parentRoutes, nextPath, nextParentRouteUrl); } } }); @@ -210,7 +205,7 @@ const getRoutes = function ({ config, absPagesPath }) { const routes = []; cacheGenRoutes = {}; - genRoutes(routes, absPagesPath, '/', config); + genRoutes(routes, absPagesPath, '/'); rank(routes); return routes; }; diff --git a/packages/fes-template/src/pages/@id/add.vue b/packages/fes-template/src/pages/@id/add.vue new file mode 100644 index 00000000..e69de29b