Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use relativeTo property in html template along with routerActive?

I need to use 'relativeTo' property as well as 'routerLinkActive' directive in my application. Having a click listener function that routes using

router.navigate(this.router.navigate(['path']{relativeTo:this.route});

would be okay. But in that case I cannot use the routerLinkActive directive.

How can I simultaneously use both?

like image 469
CKA Avatar asked Aug 09 '17 03:08

CKA


People also ask

What is relativeTo in Angular?

The object { relativeTo: this. router} ensures that the path remains relative to its parent path.

How do I set my router to active links?

Create the header component that contains the navigation links. Then apply the “routerLinkActive” on each router link and provide the CSS class to this property. Here we have created the “active” class in CSS file. Provide the { exact : true } to the root route to avoid multiple active router links.

Where would you define child URL routes?

Just like we had a <router-outlet></router-outlet> for the root application component, we would have a router outlet inside the ProductDetails component. The components corresponding to the child routes of product-details would be placed in the router outlet in ProductDetails .

How do I know if my routerLink is active?

routerLinkActive is simply an indicator of whether this link represents the active route. @jessepinho - Tried it - [routerLinkActive]="'active'" will only work if you also have [routerLink] in the a-tag. If you had (click)="navitageTo('/route')" instead of [routerLink], and in that function, you called this.


1 Answers

RelativeTo is by default set to currently activated route. In template you can use . or ^ in route name.

More about relative navigation:
https://stackoverflow.com/a/38808116/1356669
https://angular.io/guide/router#relative-navigation

like image 71
be4code Avatar answered Oct 17 '22 21:10

be4code