Skip to content

Instantly share code, notes, and snippets.

@daffl
Created November 18, 2013 20:27
Show Gist options
  • Select an option

  • Save daffl/7534728 to your computer and use it in GitHub Desktop.

Select an option

Save daffl/7534728 to your computer and use it in GitHub Desktop.
Routing control with replacements
can.Control.extend({
setControl: function(Ctrl, options) {
if(this.current) {
this.current.destroy();
}
this.current = new Ctrl(this.element, options || this.options);
},
route: function() {
this.setControl(MyControl)
},
'some/:name route': function(data) {
this.setControl(OtherControl, data);
},
'other/:id route': function(data) {
this.setControl(FooControl, data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment