I have single page web application is written on backbonejs. I use different routes and each route corresponds a controller. When I load my app root URL (myapp.com/) or any non-root URL without params (myapp.com/somelocation) it works correctly. But when I try to load my app directly to any location with query params (i.e. myapp.com/somelocation?z=search) I have some trouble. App renders twice - first with correct controller that correspond to myapp.com/somelocation?z=search and second time with controller that correspond to myapp.com/somelocation.
Routes table look like this:
routes: {
'login': 'login',
'home': 'home',
'timeline?*query': 'timelineWithQuery',
'timeline': 'timeline',
...
'*path': 'defaultRoute'
}, ...
Controllers look like this:
defaultRoute: function() {
router.navigate('home', {trigger: true});
},
login: function(args) {
var controller = new App.PageController.Mobile.AuthPageController($('body'));
controller.executeLogin(args);
},
timeline: function(args) {
var controller = new App.PageController.Mobile.TimelinePageController($('body'));
controller.executeTimeline(args);
}, ...
Document.ready script looks like this:
// ...
router.navigate(window.location, {trigger: true});
// ...
If I don't call router.navigate(window.location, {trigger: true}); explicitly no one controller renders my application start page. When I call it app works correctly until I try to start from myapp.com/timeline?foo=bar URL. And if I do this my app is rendered twice (without page reloading).
Any suggestions? What is common document.ready bootstrap pattern for backbonejs-driven single page apps with rich routing scenarios?