@@ -21,37 +21,16 @@ exports.pathsToModuleCode = function (files) {
21
21
return code
22
22
}
23
23
24
- exports . getPageComponentsLoadingFile = function ( pages ) {
25
- let code = 'const _l = {}\n'
26
-
27
- code += pages . map ( ( { filepath, key } ) => {
28
- return `_l['${ key } '] = () => import('${ filepath } ')`
29
- } ) . join ( '\n' )
30
-
31
- code += `\n\nexport default function loadComponent(key) {
32
- return _l[key]()
33
- }\n`
34
- return code
35
- }
36
-
37
24
exports . genRoutesFile = async function ( {
38
25
siteData : { pages } ,
39
26
plugin
40
27
} ) {
41
- await writeTemp ( 'components-loader.js' , exports . getPageComponentsLoadingFile ( pages ) )
42
-
43
28
function genRoute ( { path : pagePath , key : componentName } , index ) {
44
29
let code = `
45
30
{
46
31
name: ${ JSON . stringify ( componentName ) } ,
47
32
path: ${ JSON . stringify ( pagePath ) } ,
48
- component: ThemeLayout,
49
- beforeEnter: (to, from, next) => {
50
- loadComponent(${ JSON . stringify ( componentName ) } ).then(comp => {
51
- Vue.component(${ JSON . stringify ( componentName ) } , comp.default)
52
- next()
53
- })
54
- }
33
+ component: ThemeLayout
55
34
}`
56
35
57
36
const dncodedPath = decodeURIComponent ( pagePath )
@@ -94,11 +73,11 @@ exports.genRoutesFile = async function ({
94
73
`import Vue from 'vue'\n` +
95
74
`import ThemeLayout from '@themeLayout'\n` +
96
75
`import ThemeNotFound from '@themeNotFound'\n` +
97
- `import { injectMixins } from '@app/util'\n` +
98
- `import loadComponent from '@temp/components-loader'\n` +
76
+ `import { injectMixins, loadComponent } from '@app/util'\n` +
99
77
`import rootMixins from '@temp/root-mixins'\n\n` +
100
78
`injectMixins(ThemeLayout, rootMixins)\n` +
101
79
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
80
+ `${ pages . map ( ( { filepath, key } ) => `Vue.component('${ key } ', () => import('${ filepath } '))` ) . join ( '\n' ) } \n\n` +
102
81
`export const routes = [${ pages . map ( genRoute ) . join ( ',' ) } ${ notFoundRoute } \n]`
103
82
)
104
83
}
0 commit comments