Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get previous router/url in backbone application

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.

like image 488
Roy M J Avatar asked Sep 11 '13 07:09

Roy M J


1 Answers

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);
});
like image 82
Vitalii Petrychuk Avatar answered Sep 22 '22 14:09

Vitalii Petrychuk