Backbone.js PushState True

前端 未结 2 711
天涯浪人
天涯浪人 2020-12-19 20:07

I\'ve created a site in backbone and for various reasons I\'ve decided I want to remove the hash in the URL. I\'ve changed history.start from



        
2条回答
  •  臣服心动
    2020-12-19 20:33

    You need to prevent a element to carry on its regular action and have backbone router route it.

    I'll write the example using jQuery to outline what should happen:

    $(document).on("click", "a", function(e)
    {
        e.preventDefault(); // This is important
    
        var href = $(e.currentTarget).attr('href');
    
        router.navigate(href, true); // <- this part will pass the path to your router
    
    });
    

提交回复
热议问题