0
votes

I have the same problem like its asked here Routing problems with Codeigniter and Backbone.js - so, is there an existing example how this is solved? How and where do I have to adjust my code? And how do I dump Codeigniters View part and let Backbone do the complete MV part like it is suggested?

Thanks in advance...

[UPDATE] So, after looking at Catch-all Controller/Route, in my application->config->routes.php Do I have to add:

$route['(:any)'] = 'catchall_controller'

additionally to $route['default_controller'] = "main" or instead of that?

then in my main Controller I have to do this or what?:

class Main extends CI_Controller {

   public function index()
   {
    $this->uri->segment(n);
    $this->load->view('home');
   }

}

Finally remove the pushState:true in my Backbone App so it says:

 Backbone.history.start({root: App.ROOT });

is this correct?

1
Are you using pushState: true when starting Backbone.history ? - David Sulc
Yes, my main.js file contains Backbone.history.start({ pushState: true, root: App.ROOT }); - SHT

1 Answers

0
votes

Your problem comes from the fact you're using pushState. From the documentation (http://backbonejs.org/#History):

Note that using real URLs requires your web server to be able to correctly render those pages, so back-end changes are required as well. For example, if you have a route of /documents/100, your web server must be able to serve that page, if the browser visits that URL directly.

So your options are basically:

  • stop using pushState Backbone.history.start({ root: App.ROOT });
  • make your server return a valid response for every URL your Backbone app can generate (see Catch-all Controller/Route) You're running into issues because your client-side applications is generating URLs that your serever doesn't know how to process => 404 error

See also Backbone router: Use hashbangs