@@ -352,7 +352,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
352352 return extend ( { app } , option )
353353}
354354
355- export function processAppOption ( { firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el } ) {
355+ export function processAppOption ( { firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el, useSSR } ) {
356356 if ( ! isBrowser ) {
357357 return context => {
358358 const { app, router, pinia = { } } = createApp ( {
@@ -379,7 +379,7 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
379379 }
380380 }
381381 } else {
382- const { app, pinia } = createApp ( {
382+ const { app, pinia, router } = createApp ( {
383383 App,
384384 componentsMap,
385385 Vue,
@@ -391,6 +391,14 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
391391 if ( window . __INITIAL_STATE__ && pinia ) {
392392 pinia . state . value = window . __INITIAL_STATE__
393393 }
394- app . $mount ( el )
394+ if ( useSSR ) {
395+ // https://v3.router.vuejs.org/api/#router-onready
396+ // ssr 场景如果使用了异步组件,需要在 onReady 回调中挂载,否则 hydrate 可能会报错
397+ router . onReady ( ( ) => {
398+ app . $mount ( el )
399+ } )
400+ } else {
401+ app . $mount ( el )
402+ }
395403 }
396404}
0 commit comments