Routing problems with Codeigniter and Backbone.js

后端 未结 2 1868
-上瘾入骨i
-上瘾入骨i 2021-02-06 14:18

Here are the frameworks I am using:

  • Codeigniter
  • Codeigniter REST API
  • Require.js
  • Backbone.js

Runn

相关标签:
2条回答
  • 2021-02-06 14:56

    Another way to keep your browser from submitting the http request with the HREF link is to just override it with javascript and jquery. Could be useful if you don't want to always use hashtags as Loamhoof suggested.

    Example:

    $('#linkID').on('click', function(event) {
    
        event.preventDefault();
    
        backboneRouter.navigate($(event.currentTarget).attr('href'), { trigger:true });
    
    });
    
    0 讨论(0)
  • 2021-02-06 15:02

    If you're not already doing it, you may want to route via Backbone through the hashtag changes (it's his normal behavior, pushState: false), as modifying the hashtag would in no way result in a server call, thus ignoring Codeigniter's router.
    In your example, you would want to navigate to localhost/#otherPage.
    Then use Codeigniter's router for your ajax REST calls.

    0 讨论(0)
提交回复
热议问题