Angular 16 Get the Current Route Example
In this tutorial, we will go through the angular 16 get current route demonstration. You can observe how angular 16 obtains the current route path. Explain angular 16 step by step to acquire the present path. If you're looking for an example of how to retrieve the current route in Angular 16, you've come to the correct spot. To find out how to retrieve the current route name in Angular 16, follow the steps below.
To retrieve the current route in the component file, we'll utilize the angular Router module. With Router, we can simply obtain the current route path.
In the angular application, we may need to access the current path or current router URL from time to time. So, if you require it right away, I will assist you.
You can retrieve the current route name as shown below; I have included a complete example with output:
this.router.url;
This is the code for the complete example:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-posts',
templateUrl: './posts.component.html',
styleUrls: ['./posts.component.css']
})
export class PostsComponent implements OnInit {
constructor(private router: Router) { }
ngOnInit() {
console.log(this.router.url);
}
-
Date: