骨干线路 - 检测浏览器后退按钮preSS [英] backbone routes – detecting browser back button press

查看:95
本文介绍了骨干线路 - 检测浏览器后退按钮preSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法,当用户有$ P $在其浏览器pssed前进/后退键来检测。

I am trying to find a way to detect when the user has pressed the back / forward button in their browser.

我使用的骨干来处理路线,沿着主干来呈现自己的看法。

I am using backbone to handle routes, along with backbone to render my views.

问题是我不能钩到这个页面更改事件从任何地方。

The issue is I can not hook into this page change event from anywhere.

我试图把日志在我的观点我的初始化函数..但是当我使用后退按钮它不跳闸。

I tried putting a log in my initialize function for my views .. but it is not tripped when i use the back button.

我真的不知道怎么回事,来检测这个页面的变化。

I am really not sure how else to detect this page change.

推荐答案

您应该使用 Backbone.Router ,并确保你不要忘了 Backbone.history.start()启动应用程序时

You should use Backbone.Router and make sure that you don't forget about Backbone.history.start() when starting your application.

一些有用的信息可以这里发现的这里

Some useful information can be found here and here

其实第二个环节是不是文章,但一个博客。和谁写的家伙真的好像知道很多的话题。

Actually the second link is not an article, but a blog. And the guy who wrote it really seems to know a lot about the topic.

UPD:这个想法是,骨干路由器火绑定方法时,你的URL变化。所以你刚才应该把你的逻辑,这种方法和这种方式,您将能够跟踪。也许这是非常非自动方式,并且将需要编写一些code,但我认为它应该工作。

UPD: The idea is that backbone's router fire binded methods when your url changing. So you just should put your logic to this method and this way you will able to track that. Maybe it's non very automatic way, and it will take to write some code but I think it should work.

这篇关于骨干线路 - 检测浏览器后退按钮preSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆