0

I don't know how to fully explain what I want to achieve but let me fill you in.

I have registered routes on my router.

routes: {
    "" : "home",
    "form/:formID/question/:questionID" : "showResults"
}

I enabled pushState

window.base = '/make/search/';
Backbone.history.start({pushState: true, root: base});

When I use and run directly on the code.

router.navigate('form/87463636234/question/2', {trigger: true});

It get redirected to this URL

http://example.com/make/search/form/87463636234/question/2

Which is correct. so yeah it all works fine, but the thing I really wanted When I visit the link from the address bar typing exactly as that, I want it to properly load the page, normally we use the (#) hash to fully navigate with the routes.

This one works:

http://example.com/make/search/#form/87463636234/question/2

But I would like to make this work when I hit enter to address bar of the browser, getting rid of the hash from the URL.

http://example.com/make/search/form/87463636234/question/2

Unfortunately now its not, I'm getting an error page.

Hope you can help me.

Thanks in advance

UPDATE: After further research, rewrite rule seems to be the solution, however I'm not good on that, maybe can anyone guide me on how to do so. Thanks

laser
  • 1,388
  • 13
  • 14
Kenneth P.
  • 1,797
  • 3
  • 21
  • 31

1 Answers1

1

You have to configure your webserver to serve your html page with backbone application by all urls including http://example.com/make/search/form/87463636234/question/2. If you are using some web framework just configure it to return this page instead of 404 error.

Artem Volkhin
  • 1,362
  • 8
  • 22
  • I believe it has something to do with rewrite rule? when I continued my research, but still no luck doing that. – Kenneth P. Jul 23 '13 at 15:41
  • What webserver do you use? For nginx see http://stackoverflow.com/questions/9184959/rewriting-nginx-for-pushstate-urls, for apache - http://stackoverflow.com/questions/11404567/backbone-js-router-using-pushstate-with-xampp-apache-server-on-localhost – Artem Volkhin Jul 23 '13 at 16:33