Directives
Setup
Before we start using routeshub directives, we need to import the navigation module to get access.
Import example:
...
import { NavigationModule } from 'routeshub';
...
@NgModule({
imports: [
...
NavigationModule
],
...
})
export class AppModule {
}Navigation
Routeshub provides a directive navLink for navigation reasons. It extends by routerLink and doing the same as routerLink . But if you replace routerLink with navLink, then and want to pass parameters, don't forget to use navParams . navLink manages dynamic paths (parameters) with the additional attribute navParams .
Usage example:
<li [navLink]="locationUnit.map.state">Map</li>
<li [navLink]="locationUnit.search">Search</li>
<li [navLink]="locationUnit.profile.state"
[navParams]="{id: USER_ID}">
Profile
</li>As you could see, we can pass in the navLink route's state or it also possible to omit the state, and then navLink itself will still handle the link.
Summing navLink works in the same way as routerLink. It consumes the string or array of strings. But first and foremost, this directive was created for navigation through route states and support dynamic parameters via states.
Active Link
Because we replaced routerLink with navLink, then we need another directive to manage active links. Routeshub has navLinkActive for these reasons
Usage example:
<nav class="menu">
<a [navLink]="aboutUnit.root" navLinkActive="about about-active">About</a>
<a [navLink]="locationUnit.map" [navLinkActive]="['location', 'map-active']">
Map
</a>
</nav>