javascript 在主干应用程序中获取以前的路由器/url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18735111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:00:52  来源:igfitidea点击:

Get previous router/url in backbone application

javascriptbackbone.jsbackbone-routing

提问by Roy M J

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 #/currentfrom #/test1and also in another instance, from #/test1.

#/current#/test1,在另一个例子中,从#/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.

这只会给我当前访问的路线,而不是从哪条路线。

回答by Vitalii Petrychuk

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);
});