5

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'];
  })
2
  • You could store the params in a global service. Commented Jun 30, 2017 at 14:00
  • Using a route configuration like this you won't be able to. Ploppy has given the right solution, global service and BehaviorSubject is probably what you'll want to use. Commented Jun 30, 2017 at 14:27

1 Answer 1

2

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't hide parameter values
Works perfect for Angular 8 , Thank You

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.