问题
I have a backbone application and i would require to know the router from which the current route is accessed. Is it possible?
For eg :-
I reach #/current
from #/test1
and also in another instance, from #/test1
.
So can i know through some way to detect the previous router hit?
Ive used :
Backbone.history.fragment
and this only gives me the current route accessed and not from which route.
回答1:
You can store your history in some array and do some manipulation with last/previous items.
var history = [];
this.listenTo(this, 'route', function (name, args) {
history.push({
name : name,
args : args,
fragment : Backbone.history.fragment
});
console.log(history);
});
来源:https://stackoverflow.com/questions/18735111/get-previous-router-url-in-backbone-application