get url path in angular code example
Example 1: get current url angular
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
template: 'The href is: {{href}}'
})
export class Component {
public href: string = "";
constructor(private router: Router) {}
ngOnInit() {
this.href = this.router.url;
console.log(this.router.url);
}
}
Example 2: angular get route url
this.router.events
.pipe(filter( event => event instanceof NavigationEnd))
.subscribe(event => {
this.router.navigate(['/tabs']);
}
});