I have a php page that is loaded up via a get request and contains multiple params like: index.php?page=6&name=Virginia. Once the page is loaded I then initalize backbone and am using it to render views on a portion of the page. The problem is that the router appears to be taking my entire url and registering it so that in order to trigger a route I have to append the following to my links: . This works but it's ugly. I've tried changing the root parameter to Backbone.history.start but can't seem to get it to work right. I'm sure most people don't start backbone from a dynamic page with query params but any help is appreciated. I've tried various solutions from plugins to different regexes but to no avail.
Asked
Active
Viewed 588 times
0
-
This is not a typical Backbone router case. Is your pushState true or false? – mvbl fst Jul 20 '12 at 21:54
-
I know it's not typical but I've tried setting both pushState to true/false and was unsuccessful in either event. – Jul 20 '12 at 22:23
1 Answers
0
Without pushState you can't do this at all. I would do something like:
var router = Backbone.Router.extend({
routes: {
'*url': 'defaultRoute'
},
defaultRoute: function(url) {
// just url argument and parse params out
}
});
That in fact would be the easiest in your case. And for params, you need a class with get
, set
, and delete
methods, that's pretty simple and you can find a ton of examples.

mvbl fst
- 5,213
- 8
- 42
- 59
-
Thanks for the example but this still won't work as I still need to match the query params in the links otherwise backbone won't intercept the event correctly and the browser navigates away. – Jul 20 '12 at 22:50
-
No, actually this will catch ALL url changes. BTW you never showed your code. At least it would help if you showed `routes` declaration. – mvbl fst Jul 20 '12 at 22:52
-
Hi again, it doesn't catch all url changes (I'm running a super simplified example right now with just the code snippet you've posted) and it still doesn't work. After debugging backbone a bit, I believe the problem is this: a) backbone registers changes to the url by calling: $(window).bind('hashchange', this.checkUrl); . In order for this event to be properly fired, I need to keep the same dynamic parameters in the link that fires the click event, otherwise backbone is never notified of the change. I suppose this is more of a implementation of the haschange event. – Jul 20 '12 at 23:17