ItSolutionStuff.com

Angular 16 Get the Current Route Example

By Hardik Savani • October 20, 2023
Angular

Hello Folks,

In this tutorial, we will go over the demonstration of angular 16 get current route. you can see angular 16 get current route path. step by step explain angular 16 get current route. if you want to see an example of how to get current route in angular 16 then you are in the right place. follow the below step for how to get current route name in angular 16.

we will use the angular Router library to get the current route in the component file. we can easily get the current route path with Router.

We might be some time need to get the current path or current router URL in the angular application. so if you need it now then I will help you how you can get the current URL in angular. so you can see the basic solution below:

You can get the current route name like as below, i also wrote full example with output so, you can understand:

this.router.url;

window.location.href;

Now i will give you full example. you can write code on your component file as like bellow:

Component File

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);

console.log( window.location.href);

}

}

You can see output also.

Output:

/posts

http://localhost:4200/posts

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular 16 Install Font Awesome Icons Example

Read Now →

Angular 16 CRUD Application Tutorial Example

Read Now →

Angular 16 Integrate Google Maps Example

Read Now →

Angular 16 Stripe Payment Integration Example

Read Now →

Angular 16 Google Social Login Example Tutorial

Read Now →

Angular 16 HttpClient & Http Services Tutorial

Read Now →

Angular 16 Pagination with NGX Pagination Example

Read Now →

Angular 16 RxJS Observable with Httpclient Example

Read Now →

Angular 16 Routing and Navigation Example Tutorial

Read Now →

Angular 16 Service Tutorial with Example

Read Now →

Angular 16 Template Driven Form Validation Example

Read Now →

Angular 16 Multiple File Upload Example Tutorial

Read Now →

Angular 16 Multiple Image Upload with Preview Example

Read Now →

Angular 16 Material Datepicker Example Tutorial

Read Now →

Angular 16 Install Moment JS Example

Read Now →