Skip to content

Commit f4e3588

Browse files
author
wangsz
committed
fix: 修复/config无法重定向到/config/
1 parent f9de5e2 commit f4e3588

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: lib/prepare/codegen.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ exports.genRoutesFile = async function ({
66
sourceDir,
77
pageFiles
88
}) {
9-
function genRoute ({ path: pagePath, key: componentName }, index) {
9+
function genRoute({ path: pagePath, key: componentName }, index, pages) {
1010
const file = pageFiles[index]
1111
const filePath = path.resolve(sourceDir, file)
1212
let code = `
1313
{
1414
name: ${JSON.stringify(componentName)},
1515
path: ${JSON.stringify(pagePath)},
1616
component: ThemeLayout,
17+
pathToRegexpOptions: {
18+
strict: true
19+
},
1720
beforeEnter: (to, from, next) => {
1821
import(${JSON.stringify(filePath)}).then(comp => {
1922
Vue.component(${JSON.stringify(componentName)}, comp.default)
@@ -37,6 +40,14 @@ exports.genRoutesFile = async function ({
3740
path: ${JSON.stringify(pagePath + 'index.html')},
3841
redirect: ${JSON.stringify(pagePath)}
3942
}`
43+
const dirPath = pagePath.replace(/\/$/, '')
44+
if (!pages.find(page => page.path === `${dirPath}.html`) && dirPath) {
45+
code += `,
46+
{
47+
path: ${JSON.stringify(dirPath)},
48+
redirect: ${JSON.stringify(pagePath)}
49+
}`
50+
}
4051
}
4152

4253
return code
@@ -60,7 +71,7 @@ exports.genRoutesFile = async function ({
6071
}
6172

6273
exports.genComponentRegistrationFile = async function ({ sourceDir }) {
63-
function genImport (file) {
74+
function genImport(file) {
6475
const name = fileToComponentName(file)
6576
const baseDir = path.resolve(sourceDir, '.vuepress/components')
6677
const absolutePath = path.resolve(baseDir, file)

0 commit comments

Comments
 (0)