Reputation: 1838
I'm using React Router v4 and I was wondering how I can change an url without reloading the page.
If I go to http://mywebsite.com/post/245 the correct blog post loads in but I want to change the id with the name of the title of the current blog post.
My route looks like this
<Route path='/post/:id' component={BlogPost}/>
Edit: I'm not searching for a way of how I can navigation programmatically to another component. I'm searching for a way to rewrite an id to the title of my post without redirecting.
Upvotes: 2
Views: 750
Reputation: 3830
I am kind of searching for the same question, there are a few options I can think of.
If you are doing that for google search reason, you can use /:id/some-title
. Just do not use exact
in react router.
Mod rewrite, you do this on your server with nginx, or apache.
Search by unique title name.
Obviously they all have problems, but depends on what you need, one could be the solution.
Upvotes: 1