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 11import { pagesComponents } from '@internal/pagesComponents'
2+ import type { PageData } from '@vuepress/shared'
23import { removeEndingSlash } from '@vuepress/shared'
34import {
45 createMemoryHistory ,
@@ -32,13 +33,23 @@ export const createVueRouter = (): Router => {
3233 } ,
3334 } )
3435
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
3540 router . beforeResolve ( async ( to , from ) => {
3641 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 ( [
3943 resolvers . resolvePageData ( to . name as string ) ,
4044 pagesComponents [ to . name as string ] ?. __asyncLoader ( ) ,
4145 ] )
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
4253 }
4354 } )
4455
You can’t perform that action at this time.
0 commit comments