[英]How do I change the URL without causing Backbone to re-render the page?
I have a Backbone app. 我有一个Backbone应用程序。
In one area, there are subviews. 在一个区域中,有子视图。 These are correctly routed through from the Backbone router. 这些是从骨干路由器正确路由的。
routes: { primary-view(/:subview): 'someFunction' }
So I end up with a URL like: #/primary-view/subview
所以我最终得到一个URL,例如: #/primary-view/subview
I want to keep the URL up to date whenever a user clicks a menu item that changes the subview. 每当用户单击更改子视图的菜单项时,我都希望URL保持最新。 These clicks are handled within the primary view so that the only part of the page that is re-rendered, when the user clicks one of these links, is the div containing the subview. 这些单击是在主视图中处理的,因此,当用户单击这些链接之一时,重新呈现的页面的唯一部分是包含子视图的div。
I have tried: 我努力了:
Backbone.history.navigate('#/primary-view/' + subview, {trigger: false});
And: 和:
window.location.hash = '#/primary-view/' + subview;
But both of these cause the entire primary view to be re-rendered. 但是,这两者都会导致重新渲染整个主视图。
Normally this can be achieved with router.navigate . 通常,这可以通过router.navigate实现。
Whenever you reach a point in your application that you'd like to save as a URL, call navigate in order to update the URL. 每当您在应用程序中到达要另存为URL的位置时,请调用Navigation以更新URL。
In your case you should remove hash from the URL 根据您的情况,您应该从网址中删除哈希
Backbone.history.navigate('/primary-view/' + subview, {trigger: false});
or 要么
router.navigate('/primary-view/' + subview)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.