Is there a way to find out from which route he switched to the current route in Amber?
Let's say we have 3 routes: A, B and C
There is a possibility to go from A to C. Or from B to C.
A -> C
B -> C
On route C, I would like to know which route he came from. Either A or B. Is there an easy way to find this?
PS What I'm going to do is add an extra parameter with the route name (A or B) when going from A (or B) to C and get that parameter on the hook of beforeModel
route C.
source to share
Based on How do I get the current route name?
I added a property previousRoute
. It's easier than using query parameters.
Decision:
App = Ember,Application.create({
currentPath: '',
previousPath: null
});
ApplicationController : Ember.Controller.extend({
currentPathDidChange: function() {
App.set('previousPath', App.get('currentPath'));
App.set('currentPath', this.get('currentPath'));
}.observes('currentPath')
});
The properties can be accessed using:
App.get('currentPath');
App.get('previousPath');
source to share
Request parameters can be set in the following ways: controller / route And access them in the route
beforeModel:function(transition){
transition.queryParams
}
So from a, you set the request parameter to and do what you want before using the A-based Model, same for B
source to share