With the redirect hook (or afterModel), it adds an interesting dilemma where if a user hits a route that’s sole purpose is to redirect to another route, a history entry is added to the redirect route. Hence hitting back on the browser, just sends them to the redirect hook and sending them right back to where they attempted to leave. The router supports replacing the current url (as opposed to updating the url). The transition object also has a property on it called urlMethod which helps decide whether to replace or update. That being said, there is no official way to set this property.
In my example below, the referrer is unaware of the first songs id, but is aware of the album id. If that was common knowledge we wouldn’t use a redirect hook, we’d just send it there in the first place and skip the redirect route.
var firstSong = this.modelFor(‘album’).get(‘songs.firstObject’);
var trans = this.transitionTo(‘songs.view’, firstSong);
// terrible hack to modify the transition object, and trick it into replacing the url instead or updating it
trans.urlMethod = “replace”;
I’m not sure if there is a better way to do this, or if this was the intended way to do it. If so I’ll update the documentation to explain it.
It’d be nice if we could send in an options hash for the transitionTo route, but alas, I realize params 2+ are models for the transition.