javascript 使用相同的 URL 哈希刷新 BackboneJS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9932886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:17:10  来源:igfitidea点击:

Refresh BackboneJS on with same URL hash?

javascriptbackbone.jspage-refresh

提问by kidcapital

My current backbone application has a url:

我当前的主干应用程序有一个 url:

localhost/#users

Is there a way to access localhost/#userswhile at the URL localhost/#usersso it refreshes the page?

有没有办法localhost/#users在 URL上访问以localhost/#users刷新页面?

Currently, when I am at localhost/#usersand I try

目前,当我在localhost/#users和我尝试

window.location.hash = #usersor myBackboneRouter.navigate("users")

window.location.hash = #users或者 myBackboneRouter.navigate("users")

it does not trigger a page refresh.

它不会触发页面刷新。

采纳答案by heavi5ide

I think myBackboneRouter.navigate("users", {trigger: true})will do what you want.

我想myBackboneRouter.navigate("users", {trigger: true})会做你想做的。

回答by Fizer Khan

To refresh same page in backbone, you have to use

要刷新主干中的同一页面,您必须使用

Backbone.history.loadUrl(Backbone.history.fragment);

回答by Neel Shah

I use these three line of codes to reload my backbone page:

我使用这三行代码来重新加载我的主干页面:

router.navigate(Backbone.history.fragment, true);
Backbone.history.loadUrl( Backbone.history.fragment );
router.refresh(true);

OR Simply

或简单地

Backbone.history.loadUrl(Backbone.history.fragment);

回答by Ronan

Why wouldn't you use

你为什么不使用

window.location.reload();

Either that or recall your view render() function..

要么是那个,要么回忆你的视图 render() 函数..