How to get current URL and its query parameter or string in Angular 5?

Sometimes we need current URL to maintain history or passing query string data to different page. So here are codes for that

Step 1: For getting current URL:

First you need to add module ActivatedRoute from @angular/router like below:
import { Router, RouterModule, ActivatedRoute, Params } from '@angular/router';

Then define it into constructor like below:
constructor(private router : ActivatedRoute){}

Now you can get current URL on your function like below:
VAR CURRENT_URL = this.router.snapshot.url;

Step 2: For getting query strings:

Let assume that you have action and target query parameter into your URL then You can use code like below:

this.router.queryParams.subscribe(params => {
var action = params['action'];
var target = params['target'];


Please do feel free to let us know if you are facing any issues in above mentioned customization or looking for more customization in URL for Angular.

We have excellent Angular expertise and we are providing world class Angular development services in London (United kingdom), Singapore, Australia and New Zealand.