From 10f38bb1cf488d6fd4a942096ff30ac0e050983b Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Wed, 6 Jun 2018 12:26:44 +0800 Subject: [PATCH] no message Former-commit-id: cffb2fc3fd9e4c732b4ec46adceafd6728df8d0f Former-commit-id: 688946554293716950dd891134301f2253f8b465 Former-commit-id: ac5933f85b0e18d3f9781d4fb33cc6ab0e39912e --- src/router/index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 3fd28476..9a920a94 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,30 +3,28 @@ import VueRouter from 'vue-router' import Cookies from 'js-cookie' // import _path from 'path' -import _path2 from 'path-posix' +import pathPosix from 'path-posix' import _get from 'lodash.get' // import _replace from 'lodash.replace' -console.log(_path2) +console.log(pathPosix) Vue.use(VueRouter) -const path2Posix = pathString => pathString.split(_path2.sep).join('/') +const path2Posix = pathString => pathString.split(pathPosix.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 pagePath = _path2.dirname(page.default.__file) + const pagePath = pathPosix.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) + const path = pagePathPosix.replace(publicPath, '').replace(new RegExp(`${pathPosix.sep}page${pathPosix.sep}`, 'g'), pathPosix.sep) console.log('path', path) - const name = namePrefix + path.split(_path2.sep).join('-').replace(/-page-/g, '-') + const name = namePrefix + path.split(pathPosix.sep).join('-').replace(/-page-/g, '-') return { path: `${path}${_get(page, 'router.pathSuffix', '')}`, name,