离开该页面Backbone.history.start()块后退按钮 [英] Backbone.history.start() blocks back button from leaving the page

查看:213
本文介绍了离开该页面Backbone.history.start()块后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经进入这个运行的几个应用程序,所以我不知道如果我做错事与骨干网的历史。这里的情况...

I've run into this on a few apps now, so I wonder if I'm doing something wrong with Backbone history. Here's the situation...

我有两页,让我们说:

index.html
app.html

索引页仅仅是一个正常的,平跟的HTML链接, app.html 页。在应用程序页面, Backbone.history.start()被称为火起来哈希状态管理,这是用来应用页面上的两个视图之间切换,说:

The index page is just a normal, flat HTML page with a link to app.html. On the App page, Backbone.history.start() is called to fire up hash state management, which is used to toggle between two views on the App page, say:

app.html#search
app.html#results

所以,导航来回#搜寻 #results 页面之间的伟大工程。没有问题存在。当您尝试使用返回按钮步骤一路回 index.html的时,会出现问题。该路径返回到索引页面包括在 app.html 停止(无散状态),在其中的骨干路由器,尽职尽责地填补缺失的哈希状态,把你回到 app.html#搜索。再次,单击后退按钮将进入 app.html ,这在缺少哈希状态再次写满...基本上,你现在陷在一个循环,并能 ŧ去从页回来。用推状态时,会发生这种行为。

So, navigating back and forth between the #search and #results pages works great. No problems there. The issue occurs when you try to use the back button to step all the way back to index.html. The path back to the index page involves a stop at app.html (no hash state), at which the Backbone router dutifully fills in missing hash state, putting you back at app.html#search. Again, clicking the back button will go to app.html, which fills in the missing hash state again... basically, you're now stuck in a loop and can't go back from the page. This same behavior occurs when using push state.

这似乎与应用程序,自动闪光了自己的路由系统在默认的页面URL顶部的潜在通病。有谁知道的一个很好的方式,以避免这种情况?

This seems like a potentially common problem with apps that automatically fire up their own routing system on top of a default page URL. Does anyone know of a good way to avoid this?

推荐答案

的问题是, app.html 没有做它自己的事情;所以,如果导航可以在某种程度上打破了应用程序。

The problem is that app.html isn't doing anything on it's own; and so, may somehow break the app if navigated.

在这种情况下,你可以做什么,而不是重定向的根路径到另一个,只是用它作为默认的页面:

In this case, what you could do is instead of redirecting the root route to another, just use it as the default page:

routes: {
  "": "search",
  "results": "results"
}

这篇关于离开该页面Backbone.history.start()块后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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