File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { pagesComponents } from '@internal/pagesComponents'
2
+ import type { PageData } from '@vuepress/shared'
2
3
import { removeEndingSlash } from '@vuepress/shared'
3
4
import {
4
5
createMemoryHistory ,
@@ -32,13 +33,23 @@ export const createVueRouter = (): Router => {
32
33
} ,
33
34
} )
34
35
36
+ // ensure page data and page component have been loaded in beforeResolve hook,
37
+ // but do not assign page data immediately to avoid mismatching between page data and route path.
38
+ let pendingPageData : PageData
39
+ let pendingToPath : string
35
40
router . beforeResolve ( async ( to , from ) => {
36
41
if ( to . path !== from . path || from === START_LOCATION ) {
37
- // ensure page data and page component have been loaded
38
- ; [ pageData . value ] = await Promise . all ( [
42
+ ; [ pendingPageData ] = await Promise . all ( [
39
43
resolvers . resolvePageData ( to . name as string ) ,
40
44
pagesComponents [ to . name as string ] ?. __asyncLoader ( ) ,
41
45
] )
46
+ pendingToPath = to . path
47
+ }
48
+ } )
49
+ // instead, assign page data in afterEach hook
50
+ router . afterEach ( ( to , from ) => {
51
+ if ( to . path !== from . path && to . path === pendingToPath ) {
52
+ pageData . value = pendingPageData
42
53
}
43
54
} )
44
55
You can’t perform that action at this time.
0 commit comments