Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to hide the params from the query string in react routing?

Is there any way to remove the query string from the url in react application?

this.history.push('component/:id')

I want id to be removed from the browser url while navigation.

like image 348
Vikas Kumar Avatar asked Sep 19 '25 11:09

Vikas Kumar


1 Answers

The Redirect and Link components both have an overloaded to prop which can either be the string like you displayed above or an object with the following keys: pathname, search, hash, state. So your Link can become something like

<Link to={pathname: '/component', state: {id: '#id'}} />

However, keep in mind that you will have to modify your Route to no longer require an id as a urlParameter and instead in your component you should use this.props.location.state.id to access the variable.

like image 107
ManavM Avatar answered Sep 22 '25 05:09

ManavM