React - inserting variable into Route path
You are creating way more work for yourself, and this is the wrong way to add variables to route. What you're looking to do is add params
to your route. In your case, you would want it to look something like this.
<Route path="/user/:userId" />
The :
is what denotes that it is a parameter, ready to render a path based on the userId
. So if you went to route /user/123
- it would be able to render user 123's data.
Here's some documentation to help you out.
https://reacttraining.com/react-router/web/example/url-params