Get previous router/url in backbone application

社会主义新天地 提交于 2019-11-30 23:10:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!