简体   繁体   English

如何更改URL而不导致Backbone重新呈现页面?

[英]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.

相关问题 使用React-Router,如何在不触发重新渲染的情况下更新URL? - With React-Router, How do I update the URL without triggering a re-render? 加载整个页面后,如何使用骨架.js(或可能不需要它)重新呈现特定元素? - How can I re-render a specific element with backbone.js(or maybe do not need it) after whole page been loaded? 如何在不触发React的重新渲染的情况下更改元素的样式? - How do I change a an element's style without triggering a re-render in React? React:如何使用map()渲染多个菜单而又不导致重新渲染? - React: How can I render multiple menus with map() without causing a re-render? 反应状态变化不会导致重新渲染 - React state change not causing re-render 如果 url 的参数发生变化,则重新加载/重新呈现页面 - 做出反应 - reload / re-render the page if the parameters of the url change - react 我可以做些什么来改变状态而不重新渲染 - what i can do for changing state without re-render 如何在不刷新页面的情况下重新渲染以显示更改? - How can I re-render to display changes without refreshing the page? 如何在不使用 state 变量的情况下实现实时重新渲染? - How do I achieve live re-render without using state variables? 在不更改模型主干的情况下重新渲染视图 - Re-render view without models changed backbone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM