loadUrl into uninitialized subroute fails
oskbor opened this issue · 3 comments
oskbor commented
Hi!
In my main router I have the following route handlers:
routes: {
'i(:source)/*subroute': 'setSource',
'view*subroute': 'invokeView',
'settings*subroute': 'invokeSettings'
},
invokeView : function (subroute) {
if(!subRoutes.view){
subRoutes.view = new ViewRouter ('view',
{createTrailingSlashRoutes: true});
}
},
invokeSettings : function (subroute) {
if(!subRoutes.settings){
subRoutes.settings = new SettingsRouter ('settings',
{createTrailingSlashRoutes: true});
}
},
setSource: function (source, subroute) {
if(this.setSourceNumberIfValid(source)){
console.log('set source to:', source, '.Routing through to:', subroute);
Backbone.history.loadUrl(subroute); // <-- This doesn't work if the subRoute isn't initialized
}
else {
console.log('invalid source: ', source);
}
}
I have currently hacked your great lib to support my use case. I did that by doing this change:
// grab the full URL
var hash;
if (Backbone.history.fragment) {
hash = Backbone.history.getFragment(Backbone.history.fragment); //Was called without an argument before
} else {
hash = Backbone.history.getHash();
}
Not sure if this is a reasonable way to do it. Will it break someone else? Would you consider supporting this usecase?
br Oskar
geekdave commented
Hi Oskar - Thanks for raising this issue. Please create a PR with your change and an associated test (that fails before your change and passes after) and we can evaluate if it's feasible.
amakhrov commented
I assume this can be closed now?