Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js URL Routing

When setting up routes on backbone.js, it seems the framework automatically preprends # to it. I.e.

routes : { "example/:id" : "handler" },

will match a link of www.example.com/#example/123

Is it possible to add the hashtag later on in the url? I'm essentially trying to build my app as www.example.com/text/#example/123 (notice the text/ before the #).

Is there anyway of doing this without altering the backbone.js framework itself?

like image 352
bijanv Avatar asked Aug 08 '11 01:08

bijanv


1 Answers

If your server serves the page containing your app to www.example.com/text, then the backbone router will handle urls like www.example.com/text#example/123. It probably isn't advisable (even if your server supports it) to serve your page on www.example.com/test/, because that url indicates that it is a folder, not a particular page.

The backbone router pretty much ignores the baseurl (except for storing it and using it with pushState and popState), so you can serve your page on any url you want.

Hope htis helps.

like image 72
idbentley Avatar answered Nov 04 '22 11:11

idbentley