Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions core/modules/url/router/beforeEach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}