Search code examples
angularangular-routerrouterlinkrouterlinkactive

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?


Solution

  • 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