Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 Fixed browser back button behaviour after clicking "x posts" on tag…
Browse files Browse the repository at this point in the history
…s screen (#1306)

closes TryGhost/Ghost#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
  • Loading branch information
kevinansfield committed Aug 29, 2019
1 parent aef588c commit 737a09e
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions app/routes/posts.js
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 737a09e

Please sign in to comment.