gpt4 book ai didi

javascript - Backbone.history.navigate(url,{trigger :true, replace: true})

转载 作者:数据小太阳 更新时间:2023-10-29 03:48:02 24 4
gpt4 key购买 nike

我使用这种方法导航到 url,触发事件而不是将 url 推送到浏览器历史记录。但是 Backbone.history.navigate(url,{trigger:true, replace: true}) 替换历史记录中以前的 url。示例:浏览器历史

之前

本地主机:端口/url

Backbone.history.navigate(url + '/list',{ trigger:true, replace: true })

预期:在路由 url + '/list' 和浏览器历史记录 localhost:port/url 上触发事件实际上:触发事件但浏览器历史记录 localhost:port/#url/list。以前的 url 被替换

最佳答案

这就是我想你问的,如果我错了请纠正我:

“如何在不更新 URL 的情况下触发 Backbone 中的路由?”

快速回答:

你不能。 replace 选项也无济于事。这是文档中的一个片段:

To update the URL without creating an entry in the browser's history, set the replace option to true.

如您所见,替换不会影响对 URL 的更新。

后续回答:

如果您不希望 URL 更新,这让我认为在您的应用程序中显示列表不是您的应用程序状态的主要更新。如果这是真的,那么根据我的经验,您不应该使用 Backbone.history 对象来管理它。

如果您直接(例如,通过函数)或间接(例如,通过调度事件)调用此功能,那么您的应用会更新,而您的网址不会。

我喜欢Derick Baily's Post关于如何设置路由器结构。虽然有点长,但值得一读。

另外,查看 David Sulc's repo为“对木偶的温柔介绍”。我知道它使用的是 Marionette.AppRouter 对象,但原则仍然正确。 Check out this file举个例子。

作为旁注,如果 # 是问题所在; check out this SO answer .但是请注意,hashChange 选项主要用于 x 浏览器兼容性 according to the docs .

关于javascript - Backbone.history.navigate(url,{trigger :true, replace: true}),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20739856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com