@@ -6,14 +6,17 @@ exports.genRoutesFile = async function ({
6
6
sourceDir,
7
7
pageFiles
8
8
} ) {
9
- function genRoute ( { path : pagePath , key : componentName } , index ) {
9
+ function genRoute ( { path : pagePath , key : componentName } , index , pages ) {
10
10
const file = pageFiles [ index ]
11
11
const filePath = path . resolve ( sourceDir , file )
12
12
let code = `
13
13
{
14
14
name: ${ JSON . stringify ( componentName ) } ,
15
15
path: ${ JSON . stringify ( pagePath ) } ,
16
16
component: ThemeLayout,
17
+ pathToRegexpOptions: {
18
+ strict: true
19
+ },
17
20
beforeEnter: (to, from, next) => {
18
21
import(${ JSON . stringify ( filePath ) } ).then(comp => {
19
22
Vue.component(${ JSON . stringify ( componentName ) } , comp.default)
@@ -37,6 +40,14 @@ exports.genRoutesFile = async function ({
37
40
path: ${ JSON . stringify ( pagePath + 'index.html' ) } ,
38
41
redirect: ${ JSON . stringify ( pagePath ) }
39
42
}`
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
+ }
40
51
}
41
52
42
53
return code
@@ -60,7 +71,7 @@ exports.genRoutesFile = async function ({
60
71
}
61
72
62
73
exports . genComponentRegistrationFile = async function ( { sourceDir } ) {
63
- function genImport ( file ) {
74
+ function genImport ( file ) {
64
75
const name = fileToComponentName ( file )
65
76
const baseDir = path . resolve ( sourceDir , '.vuepress/components' )
66
77
const absolutePath = path . resolve ( baseDir , file )
0 commit comments