Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide browser url parameter angular2 routing

how to hide browser url parameter angular2 routing? I have the following problem:

http://localhost:4200/product-detail/590f643acaa7dca998c2e5bd

I need to hide the parameter in the URL and get:

http://localhost:4200/product-detail/

The route is defined by the following code:

app.routing.ts:

 export const AppRoutes: any = [
 .....
 { path: "product-detail/:id", component: ProductDetailComponent }
 .....
 ];

ProductDetail.ts

  this.route.params.subscribe(params => {
    this.id = params['id'];
  })
like image 658
Maurizio Rizzo Avatar asked Oct 29 '22 05:10

Maurizio Rizzo


1 Answers

When navigating to the desired route, you could use skipLocationChange:

this.router.navigate(['/product-detail'], { queryParams: this.id, skipLocationChange: true});

like image 180
Zach Newburgh Avatar answered Dec 12 '22 21:12

Zach Newburgh