From 51874a3684a1b6ebaa4f01427f42d83cd885273e Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Wed, 6 Jun 2018 12:23:58 +0800 Subject: [PATCH] no message Former-commit-id: 895cafea1f1c52ad3c97240049df42d5cd4f6dc6 Former-commit-id: eab05166af79958b8a5b32cb9ddf9c7f92a51bba Former-commit-id: 4566dbc077a417b4061f65fa0fed56f458529352 --- src/router/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index aa114c50..3fd28476 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -11,12 +11,21 @@ console.log(_path2) Vue.use(VueRouter) +const path2Posix = pathString => pathString.split(_path2.sep).join('/') + const routesMaker = ({publicPath, namePrefix, req}) => { return req.keys().map(req).map(page => { + // 匹配 '/page/'(posix) 或者 '\page\'(win) const pageRegExp = new RegExp(`${_path2.sep}page${_path2.sep}`, 'g') - const path = _path2.dirname(page.default.__file) - .replace(publicPath, '') - .replace(pageRegExp, _path2.sep) + // 每个文件的路径 + const pagePath = _path2.dirname(page.default.__file) + console.log('pagePath', pagePath) + // 每个文件的路径 => posix 风格 + const pagePathPosix = path2Posix(pagePath) + console.log('pagePathPosix', pagePathPosix) + // 路由中使用的路径 + const path = pagePathPosix.replace(publicPath, '').replace(pageRegExp, _path2.sep) + console.log('path', path) const name = namePrefix + path.split(_path2.sep).join('-').replace(/-page-/g, '-') return { path: `${path}${_get(page, 'router.pathSuffix', '')}`,