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

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

问题描述

我试图找到一种方法来检测用户何时按下了浏览器中的后退/前进按钮.

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 改变时,骨干的路由器会触发绑定方法.所以你应该把你的逻辑放到这个方法中,这样你就可以跟踪它.也许这不是很自动的方式,需要编写一些代码,但我认为它应该可以工作.

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.

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

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