From 8ed92dec715b7985670bb90177136ca0e05e3da4 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 30 Apr 2018 12:09:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20404=20handling=20in=20ad?= =?UTF-8?q?min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Ghost/issues/9571 - use `replaceWith` rather than `transitionTo` so that the back button still works and doesn't immediately throw you back to the 404 page - use the new `router` service to avoid deprecation notices - update the regex replacements to work with `#` urls --- ghost/admin/app/routes/application.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/routes/application.js b/ghost/admin/app/routes/application.js index 652f0b648c..f3db797421 100644 --- a/ghost/admin/app/routes/application.js +++ b/ghost/admin/app/routes/application.js @@ -38,6 +38,9 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, { settings: service(), tour: service(), ui: service(), + // TODO: rename to `router` when we drop using of Route#router in our + // document-title util + routerService: service('router'), shortcuts, @@ -194,14 +197,19 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, { } let routeInfo = transition.handlerInfos[transition.handlerInfos.length - 1]; - let router = this.get('router'); + let router = this.get('routerService'); let params = []; for (let key of Object.keys(routeInfo.params)) { params.push(routeInfo.params[key]); } - return this.transitionTo('error404', router.generate(routeInfo.name, ...params).replace('/ghost/', '').replace(/^\//g, '')); + let url = router.urlFor(routeInfo.name, ...params) + .replace(/^#\//, '') + .replace(/^\//, '') + .replace(/^ghost\//, ''); + + return this.replaceWith('error404', url); } if (isVersionMismatchError(error)) {