Skip to main content
typescript code highlight
Source Link
Pini Cheyni
  • 5.5k
  • 2
  • 45
  • 58

Angular 7, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 
import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 7, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 7, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 
added 4 characters in body
Source Link
Druta Ruslan
  • 7.4k
  • 2
  • 31
  • 40

Angular 6Angular 7, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 6, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 7, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 
edited body
Source Link
Druta Ruslan
  • 7.4k
  • 2
  • 31
  • 40

Angular 6, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( priveteprivate router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 6, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( privete router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 

Angular 6, if you want to subscribe to router

import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; constructor( private router: Router ) { router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { console.log(event.url); }); } 
Source Link
Druta Ruslan
  • 7.4k
  • 2
  • 31
  • 40
Loading