骨干路线没有哈希?

我正在使用当前项目的骨干。 我想知道是否有可能做没有散列的路由# ,就像davis.js一样。

谢谢!

您需要启用pushState

Backbone.history.start({pushState: true})

http://backbonejs.org/#Router

http://backbonejs.org/#History

编辑:如注释中所述,这将只适用于支持pushState的浏览器,浏览器不会回退到散列方法。 没有真正的解决方法,你可以启用现代浏览器,并退回所有浏览器或只使用散列。

主干锅炉板有一个优秀的助手,使推状态。 有时我想绕过我的路由器使用它。

 // Trigger the initial route and enable HTML5 History API support, set the // root folder to '/' by default. Change in app.js. Backbone.history.start({ pushState: true, root: app.root }); // All navigation that is relative should be passed through the navigate // method, to be processed by the router. If the link has a `data-bypass` // attribute, bypass the delegation completely. $(document).on("click", "a[href]:not([data-bypass])", function(evt) { // Get the absolute anchor href. var href = { prop: $(this).prop("href"), attr: $(this).attr("href") }; // Get the absolute root. var root = location.protocol + "//" + location.host + app.root; // Ensure the root is part of the anchor href, meaning it's relative. if (href.prop.slice(0, root.length) === root) { // Stop the default event to ensure the link will not cause a page // refresh. evt.preventDefault(); // `Backbone.history.navigate` is sufficient for all Routers and will // trigger the correct events. The Router's internal `navigate` method // calls this anyways. The fragment is sliced from the root. Backbone.history.navigate(href.attr, true); } });