Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NSRouterLinkActive

The NSRouterLinkActive directive lets you add a CSS class to an element when the link"s route becomes active.

Consider the following example:

<a [nsRouterLink]="/user/bob" [nsRouterLinkActive]="active-link">Bob</a>

When the url is either "/user" or "/user/bob", the active-link class will be added to the component. If the url changes, the class will be removed.

You can set more than one class, as follows:

<a [nsRouterLink]="/user/bob" [nsRouterLinkActive]="class1 class2">Bob</a>
<a [nsRouterLink]="/user/bob" [nsRouterLinkActive]="["class1", "class2"]">Bob</a>

You can configure NSRouterLinkActive by passing exact: true. This will add the classes only when the url matches the link exactly.

<a [nsRouterLink]="/user/bob" [nsRouterLinkActive]="active-link"
[nsRouterLinkActiveOptions]="{exact: true}">Bob</a>

Finally, you can apply the NSRouterLinkActive directive to an ancestor of a RouterLink.

<div [nsRouterLinkActive]="active-link" [nsRouterLinkActiveOptions]="{exact: true}">
  <a [nsRouterLink]="/user/jim">Jim</a>
  <a [nsRouterLink]="/user/bob">Bob</a>
</div>

This will set the active-link class on the div tag if the url is either "/user/jim" or "/user/bob".

stable

Hierarchy

  • NSRouterLinkActive

Implements

  • OnChanges
  • OnDestroy
  • AfterContentInit

Index

Constructors

constructor

  • new NSRouterLinkActive(router: Router, element: ElementRef, renderer: Renderer2): NSRouterLinkActive

Properties

Private active

active: boolean

Private classes

classes: string[]

Private element

element: ElementRef

links

links: QueryList<NSRouterLink>

Private renderer

renderer: Renderer2

Private router

router: Router

Private subscription

subscription: Subscription

Accessors

isActive

  • get (): boolean

nsRouterLinkActive

  • set (data: string[] | string): void

Methods

Private hasActiveLinks

  • hasActiveLinks(): boolean

Private isLinkActive

  • isLinkActive(router: Router): function

ngAfterContentInit

  • ngAfterContentInit(): void

ngOnChanges

  • ngOnChanges(_: object): any

ngOnDestroy

  • ngOnDestroy(): any

Private reduceList

  • reduceList(currentUrlTree: UrlTree, q: QueryList<any>): boolean

Private update

  • update(): void

Object literals

nsRouterLinkActiveOptions

nsRouterLinkActiveOptions: object

exact

exact: false

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method