javascript-骨干pushState路由

我正在尝试处理steel.js pushState以在漂亮的URL上更改标签.使用本地主机,脚本的路径是http://localhost/test/backbone/test.html.但是每次单击都会把我扔到localhost /登录名.我究竟做错了什么?

var AppRouter = Backbone.Router.extend({
    routes: {
        "login": "getPost",
        "*actions": "defaultRoute"
    }
});

var app_router = new AppRouter;

app_router.on('route:getPost', function (id) {
    alert( "login" );   
});

app_router.on('route:defaultRoute', function (actions) {
    alert( actions ); 
});

app_router.navigate("/login", {trigger: true});
Backbone.history.start({pushState: true, root: '/login/'});

解决方法:

您需要添加:

$(document).delegate("a", "click", function(evt) {
    var href = $(this).attr("href");
    var protocol = this.protocol + "//";

    if (href.slice(protocol.length) !== protocol && protocol !== 'javascript://' &&      href.substring(0, 1) !== '#') {
        evt.preventDefault();

        Backbone.history.navigate(href, true);
    }
});

最后2个字符串应为:

app_router.navigate("/login", {trigger: true}); // <- should remove this string
Backbone.history.start({pushState: true, root:"test/backbone/test.html"});
上一篇:禁止浏览器后退


下一篇:java.lang.Exception: java.io.IOException: Illegal partition for解决方法