Backbone.js URL Routing
Asked Answered
P

1

9

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?

Pl answered 8/8, 2011 at 1:31 Comment(0)
A
1

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.

Arango answered 8/8, 2011 at 1:40 Comment(2)
I did manage to get it working through the URL you mentioned www.example.com/text#example/123 however it's not pretty at all and I was hoping I could get the slashes to work within there. I have my own internal routing that servers www.example.com/test and that is necessary for the app. Anyway I can specify the baseurl to include www.example.com/text and not just the domain itself?Pl
Without modification to the backbone codebase, I don't think you can achieve what you are suggesting.Arango

© 2022 - 2024 — McMap. All rights reserved.