Search code examples
javascriptangularangular2-routingangular4-router

router.navigate is not working in Angular


bellow is my redirect method which is not working

    goToProdPage() {
       this.router.navigate([this.quoteId,'/cpq']);
       window.location.reload();
    }

but if i change this to

goToProdPage() {
     this.router.navigate(['./'+this.quoteId+'/cpq']);
     window.location.reload();
}

Then its working fine. but now i'm not able to get url param(which is quoteId) from activatedRoute in other components.

bellow is routing code in app.module.ts

const appRouter :Routes = [
   {path:'login', component: loginPage},
   {path:':quoteId/cpq', component: cpqPage},
   {path:'', redirectTo:'/login', pathMatch:'full'},
]

Solution

  • You don´t need window.location.reload(); which will skip the cache and reload the same page, change it as

    goToProdPage() {
        this.router.navigate([this.quoteId, 'cpq']);   
    }