I can't seem to extend RouterOutlet when using the new router in RC.1
Example:
import { Directive } from '@angular/core';
import { Router, ROUTER_DIRECTIVES, RouterOutlet } from '@angular/router';
@Directive({
selector: 'router-outlet'
})
export class RouterOutletDirective extends RouterOutlet {
}
The error:
@angular/router/index"' has no exported member 'RouterOutlet'.
Am i doing something wrong or is this broke with the new router in RC.1?
import { Directive, Attribute, ViewContainerRef, DynamicComponentLoader } from '@angular/core';
import { Router, Routes, RouterOutletMap } from '@angular/router';
import { RouterOutlet } from '@angular/router/src/directives/router_outlet';
@Directive({
selector: 'router-outlet'
})
export class RouterOutletDirective extends RouterOutlet {
constructor(parentOutletMap: RouterOutletMap, _location: ViewContainerRef, name: string) {
super(parentOutletMap, _location, name);
console.log( parentOutletMap );
}
activate() {
console.log('Activate');
}
}
So it's now running but the RouterOutlet is underlined in red with type "any" is not a constructor function type and also the activate part doesn't work. Am i missing something?
You can have multiple router-outlet in same template by configuring your router and providing name to your router-outlet, you can achieve this as follows. Advantage of below approach is thats you can avoid dirty looking URL with it. eg: /home(aux:login) etc.
The Angular router-outlet Router-Outlet is an Angular directive from the router library that is used to insert the component matched by routes to be displayed on the screen.
In Angular, RouterLink is a directive for navigating to a different route declaratively. Router. navigate and Router. navigateByURL are two methods available to the Router class to navigate imperatively in your component classes.
RouterOutlet
and RouterLink
are not exported from @angular/router
. This was fixed already recently and I'd expect this fix to be included in RC.2.
You can import them from the private path (src/...
) as a workaround until the new version is published.
Hint
That said, there is again a new router work in progress. If you currently working on migrating from the beta router or @angular/router-derprecated
to @angular/router
it's probably better to postpone until the new new router is out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With