I want to override the Router::navigate and execute some code directly in a Router class (log for example)
export const routes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
];
export function routerFactory(rootComponentType: Type<any> | null, urlSerializer: UrlSerializer,
rootContexts: ChildrenOutletContexts, location: Location,
injector: Injector, loader: NgModuleFactoryLoader,
compiler: Compiler, config: Router): Router {
return new MyRouter(
rootComponentType,
urlSerializer,
rootContexts,
location,
injector,
loader,
compiler,
config
);
}
@NgModule({
declarations: [
AppComponent,
...
],
imports: [
routing,
...
],
providers: [
...
{
provide: Router,
useFactory: routerFactory,
deps: [Type, UrlSerializer, ChildrenOutletContexts, Location, Injector,
NgModuleFactoryLoader, Compiler, router]
}
],
bootstrap: [AppComponent]
})
With that code, i have the error:
Error: Can't resolve all parameters for routerFactory: (
[object Object],
[object Object],
[object Object],
[object Object],
[object Object],
[object Object],
[object Object],
?)
Did i miss something ? Can i override with factory the Router component ?
Why angular can't inject my routes ?