Angular Get Current Route Name Example

Angular Get Current Route Name Example

In this post we will give you information about Angular Get Current Route Name Example. Hear we will give you detail about Angular Get Current Route Name ExampleAnd how to use it also give you demo for it if it is necessary.

Here i can guide you how to get current route data in angular component. we will get angular current route name and url from component file. you can get current route path using angular router. you can easily get current route name in angular 6, angular 7, angular 8 and angular 9.

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

We might be some time need to get current path or current router url in angular application. so if you need now then i will help you how you can get current url in angular. so you can see basic solution bellow:

You can get current route name like as bellow, i also written 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:

Also see:How to get current url in Angular?

/posts

http://localhost:4200/posts

I hope it can help you…

Hope this code and post will helped you for implement Angular Get Current Route Name Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  78  =  88

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US