How to handle non-root URLs in a singlepage app?

前端 未结 3 1537
悲&欢浪女
悲&欢浪女 2020-12-31 23:56

I try to make a single page app with Rails 3.2 and Backbone.js with pushState option but faced with something that I do not understand.

If I load the root URL of the

3条回答
  •  不思量自难忘°
    2021-01-01 00:32

    Backbone will not be informed of your url change if you do it manually. This change will be catch by the browser and it will do its job sending the request to the server as usual.

    Same if you click in a normal link, it will follow its href without inform Backbone.

    If you want Backbone being in charge of a url change you have to do it through the Backbone tools you have available and this is the own Router.

    So if you want to make an URL change in the Backbone way you have to do it explicitly, something like:

    app.router.navigate("my/route", {trigger: true});
    

提交回复
热议问题