Skip to content

Commit 0581725

Browse files
author
wangsz
committed
fix: redirect fail between '/routeName' and '/routeName/'
1 parent f9de5e2 commit 0581725

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: lib/prepare/codegen.js

+12-1
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

0 commit comments

Comments
 (0)