backbone router not working without # in the URL

340 Views Asked by At

I am using backbone layoutmanager, handlebars and requirejs for my application with HtML5 and its a single page application. I am using backbone.history.start({ pushState:true }) which is helping in getting rid of # if I type URL as localhost:9090/#abc but if I paste the URL localhost:9090/abc in browser then its not routing to the correct page but its going to the routes in app.yaml.

On click event I am able to navigate to URL localhost:9090/abc,but not when I copy-paste in browser directly.

I have done a lot of research to solve the issue but no results. Any suggestion will be helpful.. thanks in advance

1

There are 1 best solutions below

0
Peter Knego On

First you should read about the # in url - the fragment identifier. To put it simply: everything before the # is routed on server, and everything after the # is routed in javascript on browser.

So when you call localhost:9090/#abc the server look for resources on /, which I guess is your JS app and returns it to browser. Browser then executes JS app, which in turn checks the identifier after # and decides what to display.

Also I'm a bit confused about what you are trying to do - are you trying to get rid of # yet at the same time have history support in JS app? Afaik this can not be done.