How to get the current URL/Route in Angular? With pure JavaScript: console . log ( window . location . href ) Using Angular: this . router . url The Examples in details - import { Component } from '@angular/core' ; import { Router } from '@angular/router' ; @ Component ({ template: 'The href link is : {{href}}' }) export class Component { public href : string = null ; constructor ( private router : Router ) {} ngOnInit () { this . href = this . router . url ; console . log ( this . href ); } } To get the route segments: import { ActivatedRoute , UrlSegment } from '@angular/router' ; constructor ( route : ActivatedRoute ) { } getRoutes () { const segments : UrlSegment [] = this . route . snapshot . url ; } //...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers