You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var Router = Backbone.Router.extend({
routes: {
'': "root",
users: "users",
test: 'test',
'*actions': 'defaultRoute'
},
test: function () {
debugger;
},
createSubRouters: function () {
require(['routers/CompanyRouter'], function (Router) {
new Router('companies', {createTrailingSlashRoutes: true});
});
...
}
The router is loaded in an Marionette App, like this:
app.js:
app.addInitializer(function () {
// we require the router here to avoid circular dependencies
require(['routers/MainRouter'], function (Router) {
app.router = new Router();
Backbone.history.start();
app.router.createSubRouters();
})
});
I just pushed v0.3.2 which should fix this issue. Basically that call to loadUrl should only have been invoked if the browser url hash actually matches the subroute being initialized. I didn't run into this myself because I am lazy-loading my sub-routes, only when they are first navigated to.
Please let me know if this fixes the issue for you.
So I have this MainRouter.js:
The router is loaded in an Marionette App, like this:
app.js:
When I go on
#/test
, the debugger is triggered when starting the history inapp.js
.However, when the subrouters are created,
Backbone.history.loadUrl
(https://github.com/ModelN/backbone.subroute/blob/master/backbone.subroute.js#L81) causes the function to be executed again.This means, that when I first time load my app, the controller/router function is executed (1 + numberOfSubRouters) times.
Can I avoid this somehow? I tried to move the
app.router.createSubRouters();
before theBackbone.history.start()
, but with no success.Any help is greatly appreciated :)
The text was updated successfully, but these errors were encountered: