Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christopherthielen/c606d3e6b056ee1ae2a57e570d5d3c55 to your computer and use it in GitHub Desktop.
Save christopherthielen/c606d3e6b056ee1ae2a57e570d5d3c55 to your computer and use it in GitHub Desktop.
otherwise thinggy
class OtherwiseRouterProvider {
constructor($urlRouterProvider) {
this.otherwiseRouters = [];
this.$urlRouterProvider = $urlRouterProvider;
}
registerRouter(func) {
this.otherwiseRouters.unshift(func);
return this;
}
$get($injector) {
let service = new OtherwiseRouter(this.otherwiseRouters);
this.$urlRouterProvider.otherwise(($injector, $location) => {
return service.route($location.path());
});
return service;
}
}
class OtherwiseRouter {
constructor(otherwiseRouters) {
this.otherwiseRouters = otherwiseRouters;
}
getRouters() {
return this.otherwiseRouters;
}
route(path) {
this.otherwiseRouters.forEach(function(router) {
router();
}, this);
}
}
OtherwiseRouterProvider.$inject = ['$injector'];
export {OtherwiseRouterProvider, OtherwiseRouter};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment