没有哈希无法获得骨干路线? [英] Can't get Backbone routes without hashes?

查看:109
本文介绍了没有哈希无法获得骨干路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个浏览器可以捕获和处理可收藏的URL。如果我只是使用的 Backbone.history.start() 的,然后我可以使用哈希的URL,例如 /#帐户

I want to have bookmarkable URLs that the browser can capture and handle. If I just use Backbone.history.start(), then I can use hash URLs, like /#accounts.

但我想没有散列的网址,一拉的 /帐户 的。但我不能得到这个使用工作的 Backbone.history.start({pushState的:真正}) 的(的正如其他人所描述的那样)。我的路线是简单,直接从文档拍摄。

But I want URLs without the hashes, a la /accounts. But I can't get this to work using Backbone.history.start( { pushState: true } ) (as others have described it). My routes are straightforward, and taken directly from the documentation.



    MyRouter = Backbone.Router.extend({
        routes: {
            '/accounts': 'accounts',
        }
    });

我在使用Chrome(也试图与FF),而行为是一个的 /帐户 的请求,径直到服务器。没有被第一骨干截获。有没有人碰到这个?如何得到
 哈希少URL与骨干处理?

I'm using Chrome (also tried with FF), and the behaviour is that an /accounts request goes straight to the server. Not being intercepted by Backbone first. Has anyone run into this? How do I get hash-less URL handling with Backbone?

在此先感谢

推荐答案

您将导航与使用 router.navigate(/账户,真)JS的网址 ,而不是链接或输入自己的网址。要使用链接,必须单击事件绑定到他们,prevent默认的动作,并调用导航到链接HREF。

You would navigate to that url with js using router.navigate( "/accounts", true ), not by links or entering the url yourself. To use links, you must bind a click event to them and prevent the default action and call navigate to the links href.

路由器路由器

这篇关于没有哈希无法获得骨干路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆