Search code examples
javascripthtmlbackbone.js

cannot change page in backbone app by typing address in browser


I'm writing a Backbone app where I enabled push state in the router

Backbone.history.start({ pushState: true});

If I click a link get beer on the homepage to go to another page-- at localhost:8080/beer--, everything works as desired. However, if I type localhost:8080/beer in the browser, I don't get the Backbone page for the Beer route, but rather the template rendered by the server (in this case, a golang backend) or, if there isn't one, a 404 message. This makes the app basically useless as I can't count on users only clicking links and not typing addresses in the browser. Is it possible to navigate to different pages of a Backbone app that uses push state by typing the address in the browser and, if so, how?


Solution

  • You should configure your backend router to map all URLs that are mapped to in your Backbone router to the html page that renders your app