How to capture the URL parameters and based in url params redirect to other component in angular4


I have two applications.
From one applications we are coming to second applications.
from the first application


while coming from first application to second application it will send some data to second application.

second application

Based on URL prams from the first application we have to redirect to specific component.

routes in angular app

{ path: ”, pathMatch: ‘full’, redirectTo: ‘/login’ },
{ path: ‘**’, pathMatch: ‘full’, redirectTo: ‘/login’ },

what is best way to achieve this?


subscribe to route events and then

ngOnInit() {
    this.sub = this.route.params.subscribe(params => { = +params['id']; // (+) converts string 'id' to a number

       // apply you condition here{

and if you want to read detailed explanation you may read this topic
using click here having good topics

also, configure you route file

  { path: 'login', component: LoginComponent },
  { path: 'nomination', component: HomeComponent }

try with NavigationEnd

previousUrl: string;
constructor(router: Router) {
  .filter(event => event instanceof NavigationEnd)
  .subscribe(e => {
    console.log('prev:', this.previousUrl);
    this.previousUrl = e.url;

Answered By – Santosh Singh

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.