File tree 4 files changed +43
-10
lines changed
packages/@vuepress/core/lib/app
4 files changed +43
-10
lines changed Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
- import components from '@internal/page-components'
3
2
4
3
export default {
5
4
functional : true ,
@@ -9,12 +8,13 @@ export default {
9
8
} ,
10
9
render ( h , { parent, props, data } ) {
11
10
const pageKey = props . pageKey || parent . $page . key
12
- if ( components [ pageKey ] ) {
11
+ if ( Vue . $vuepress . isPageExists ( pageKey ) ) {
13
12
// In SSR, if a component is not registered with the component option
14
13
// vue-server-renderer will not be able to resovle it.
15
14
if ( ! parent . $ssrContext ) {
16
- Vue . component ( pageKey , components [ pageKey ] )
15
+ Vue . $vuepress . registerPageAsyncComponent ( pageKey )
17
16
}
17
+
18
18
return h ( pageKey , {
19
19
class : [ data . class , data . staticClass ] ,
20
20
style : data . style ,
Original file line number Diff line number Diff line change 13
13
/* global CONTENT_LOADING */
14
14
15
15
import Vue from ' vue'
16
- import components from ' @internal/page-components'
17
16
import ContentLoading from ' ./ContentLoading'
18
17
19
18
const CONTENT_LOADING_COMPONENT = typeof CONTENT_LOADING === ' string'
@@ -61,26 +60,28 @@ export default {
61
60
methods: {
62
61
loadContent (pageKey ) {
63
62
this .layout = null
64
- if (components[ pageKey] ) {
63
+ if (this . $vuepress . isPageExists ( pageKey) ) {
65
64
if (! this .$ssrContext ) {
66
- Vue . component (pageKey, components[pageKey] )
65
+ this . $vuepress . registerPageAsyncComponent (pageKey)
67
66
this .layout = pageKey
68
67
}
69
68
}
70
69
},
71
70
72
71
reloadContent (pageKey ) {
73
- if (Vue .component (pageKey)) {
72
+ // When page has been loaded, disable transition.
73
+ if (this .$vuepress .isPageLoaded (pageKey)) {
74
74
this .layout = pageKey
75
75
this .noTransition = true
76
76
return
77
77
}
78
+ // Start to load unfetched page component.
78
79
this .layout = CONTENT_LOADING_COMPONENT
79
- if (components[ pageKey] ) {
80
+ if (this . $vuepress . isPageExists ( pageKey) ) {
80
81
this .noTransition = false
81
82
if (! this .$ssrContext ) {
82
83
Promise .all ([
83
- components[pageKey]( ),
84
+ this . $vuepress . loadPageAsyncComponent (pageKey ),
84
85
new Promise (resolve => setTimeout (resolve, 300 ))
85
86
]).then (([comp ]) => {
86
87
this .$vuepress .$emit (' AsyncMarkdownAssetLoaded' , this .pageKey )
Original file line number Diff line number Diff line change 1
1
import { Store } from './Store' ;
2
+ import { AsyncComponent } from 'vue'
2
3
3
4
declare class VuePress extends Store {
5
+ isPageExists ( pageKey : string ) : boolean ;
4
6
7
+ isPageLoaded ( pageKey : string ) : boolean ;
8
+
9
+ getPageAsyncComponent ( pageKey : string ) : ( ) => Promise < AsyncComponent > ;
10
+
11
+ loadPageAsyncComponent ( pageKey : string ) : Promise < AsyncComponent > ;
12
+
13
+ registerPageAsyncComponent ( pageKey : string ) : void ;
5
14
}
6
15
7
16
declare module "vue/types/vue" {
8
17
interface Vue {
9
- $vuepress : Store ;
18
+ $vuepress : VuePress ;
10
19
}
11
20
}
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
1
2
import Store from './Store'
3
+ import pageComponents from '@internal/page-components'
2
4
3
5
class VuePress extends Store {
6
+ isPageExists ( pageKey ) {
7
+ return Boolean ( pageComponents [ pageKey ] )
8
+ }
9
+
10
+ isPageLoaded ( pageKey ) {
11
+ return Boolean ( Vue . component ( pageKey ) )
12
+ }
13
+
14
+ getPageAsyncComponent ( pageKey ) {
15
+ if ( ! this . isPageExists ( pageKey ) ) {
16
+ throw new Error ( `Cannot found ${ pageKey } ` )
17
+ }
18
+ return pageComponents [ pageKey ]
19
+ }
20
+
21
+ loadPageAsyncComponent ( pageKey ) {
22
+ return this . getPageAsyncComponent ( pageKey ) ( )
23
+ }
4
24
25
+ registerPageAsyncComponent ( pageKey ) {
26
+ Vue . component ( pageKey , this . getPageAsyncComponent ( pageKey ) )
27
+ }
5
28
}
6
29
7
30
export default {
You can’t perform that action at this time.
0 commit comments