diff --git a/CHANGELOG.md b/CHANGELOG.md index 52cb2f88ee..2b049e821f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed null value of search input - @AdKamil (#3778) - Fixed product sorting - @AdKamil (#3785) - Redirect from simple product using url_path - @benjick (#3804) +- Mount app in 'beforeResolve' if it's not dispatched in 'onReady' - @gibkigonzo (#3669) ## [1.11.0-rc.2] - 2019.10.31 diff --git a/core/client-entry.ts b/core/client-entry.ts index 037d6f84c9..c3a5082ac8 100755 --- a/core/client-entry.ts +++ b/core/client-entry.ts @@ -70,17 +70,21 @@ const invokeClientEntry = async () => { }) } router.onReady(async () => { + // check if app can be mounted + const canBeMounted = () => RouterManager.isRouteDispatched() && // route is dispatched + !(router as any).history.pending && // there is no pending in router history + !(app as any)._isMounted // it's not mounted before + + if (canBeMounted()) { + app.$mount('#app') + } router.beforeResolve((to, from, next) => { if (!from.name) { - // Mounting app - if (!RouterManager.isRouteDispatched()) { - RouterManager.addDispatchCallback(() => { - app.$mount('#app') - }) - } else { + next() + if (canBeMounted()) { app.$mount('#app') } - return next() // do not resolve asyncData on server render - already been done + return // do not resolve asyncData on server render - already been done } if (Vue.prototype.$ssrRequestContext) Vue.prototype.$ssrRequestContext.output.cacheTags = new Set() const matched = router.getMatchedComponents(to)