From 4a11a72ea2a5310404d3507dd86ceb09e3af5477 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 29 Aug 2019 11:10:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20browser=20back=20button?= =?UTF-8?q?=20behaviour=20after=20clicking=20"x=20posts"=20on=20tags=20scr?= =?UTF-8?q?een=20(#1306)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/11057 - removed static "replace" configuration of posts/pages query params - used the router service to register a `willTransition` event handler which handles conditional replaceState transition behaviour only when filters are changed whilst already on the posts/pages route --- ghost/admin/app/routes/posts.js | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/ghost/admin/app/routes/posts.js b/ghost/admin/app/routes/posts.js index 1cd22a9e14..6bf36641ff 100644 --- a/ghost/admin/app/routes/posts.js +++ b/ghost/admin/app/routes/posts.js @@ -5,30 +5,36 @@ import {inject as service} from '@ember/service'; export default AuthenticatedRoute.extend({ infinity: service(), + router: service(), queryParams: { - type: { - refreshModel: true, - replace: true - }, - author: { - refreshModel: true, - replace: true - }, - tag: { - refreshModel: true, - replace: true - }, - order: { - refreshModel: true, - replace: true - } + type: {refreshModel: true}, + author: {refreshModel: true}, + tag: {refreshModel: true}, + order: {refreshModel: true} }, modelName: 'post', perPage: 30, + init() { + this._super(...arguments); + + // if we're already on this route and we're transiting _to_ this route + // then the filters are being changed and we shouldn't create a new + // browser history entry + // see https://github.com/TryGhost/Ghost/issues/11057 + this.router.on('routeWillChange', (transition) => { + if (transition.to && (this.routeName === 'posts' || this.routeName === 'pages')) { + let toThisRoute = transition.to.find(route => route.name === this.routeName); + if (transition.from && transition.from.name === this.routeName && toThisRoute) { + transition.method('replace'); + } + } + }); + }, + model(params) { return this.session.user.then((user) => { let queryParams = {};