diff --git a/CHANGELOG.md b/CHANGELOG.md index 27ef11594a..530a44f574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix low-quality images styles - @przspa (#3906) +- Fix page-not-found redirect in dispatcher - @gibkigonzo (#3956) ## [1.10.5] - 28.11.2019 diff --git a/core/modules/url/router/beforeEach.ts b/core/modules/url/router/beforeEach.ts index 72ad0d74d0..8e4b5b82db 100644 --- a/core/modules/url/router/beforeEach.ts +++ b/core/modules/url/router/beforeEach.ts @@ -28,8 +28,9 @@ export async function beforeEach (to: Route, from: Route, next) { const path = normalizeUrlPath(to.path) const hasRouteParams = to.hasOwnProperty('params') && Object.values(to.params).length > 0 const isPreviouslyDispatchedDynamicRoute = to.matched.length > 0 && to.name && to.name.startsWith('urldispatcher') - if (!to.matched.length || (isPreviouslyDispatchedDynamicRoute && !hasRouteParams)) { - UrlDispatchMapper(to).then((routeData) => { + if (!to.matched.length || to.matched[0].name.endsWith('page-not-found') || (isPreviouslyDispatchedDynamicRoute && !hasRouteParams)) { + try { + const routeData = await UrlDispatchMapper(to) if (routeData) { let dynamicRoutes: LocalizedRoute[] = processDynamicRoute(routeData, path, !isPreviouslyDispatchedDynamicRoute) if (dynamicRoutes && dynamicRoutes.length > 0) { @@ -39,28 +40,23 @@ export async function beforeEach (to: Route, from: Route, next) { }) } else { Logger.error('Route not found ' + routeData['name'], 'dispatcher')() - next(localizedRoute('/page-not-found', currentStoreView().storeCode)) + next() } } else { Logger.error('No mapping found for ' + path, 'dispatcher')() - next(localizedRoute('/page-not-found', currentStoreView().storeCode)) + next() } - }).catch(e => { + } catch (e) { Logger.error(e, 'dispatcher')() - if (!isServer) { - next(localizedRoute('/page-not-found', currentStoreView().storeCode)) - } else { - const storeCode = currentStoreView().storeCode - Vue.prototype.$ssrRequestContext.server.response.redirect((storeCode !== '' ? ('/' + storeCode) : '') + '/page-not-found') // TODO: Refactor this one after @filrak will give us a way to access ServerContext from Modules directly :-) - // ps. we can't use the next() call here as it's not doing the real redirect in SSR mode (just processing different component without changing the URL and that causes the CSR / SSR DOM mismatch while hydrating) - } - }).finally(() => { - routerHelper.popStateDetected = false + next() + } finally { RouterManager.unlockRoute() - }) + } } else { next() RouterManager.unlockRoute() routerHelper.popStateDetected = false } + + routerHelper.popStateDetected = false }