如何将“#”路由替换为标准路由
How to replace "#" routes to standard routes
例如:
在 router.js
routes: { "": "home", "first": "first" }, .....
在页面中:
<a href="#">home</a> <a href="#first">link first page</a>
在浏览器地址栏中:www.domain.com/#first
我想得到URL:www.domain.com/first
如何替换路由中的“#”?
您可以使用 Backbone.history.start({ pushState: true })
.
来自文档 (http://backbonejs.org/#History):
To indicate that you'd like to use HTML5 pushState support in your
application, use Backbone.history.start({pushState: true})
. If you'd
like to use pushState, but have browsers that don't support it
natively use full page refreshes instead, you can add {hashChange:
false} to the options.
例如: 在 router.js
routes: { "": "home", "first": "first" }, .....
在页面中:
<a href="#">home</a> <a href="#first">link first page</a>
在浏览器地址栏中:www.domain.com/#first
我想得到URL:www.domain.com/first
如何替换路由中的“#”?
您可以使用 Backbone.history.start({ pushState: true })
.
来自文档 (http://backbonejs.org/#History):
To indicate that you'd like to use HTML5 pushState support in your application, use
Backbone.history.start({pushState: true})
. If you'd like to use pushState, but have browsers that don't support it natively use full page refreshes instead, you can add {hashChange: false} to the options.