S
S
steemy_web2017-06-21 02:20:05
React
steemy_web, 2017-06-21 02:20:05

React router 4, correctly passing path parameters?

Good evening, please tell me, I'm making a router on react-router 4, or rather I started reading the manual, it was on the old version, and the question is how right I did

<Route path="/repos/details/:repo_name"
render={({match}) => <RepoDetails repo_name={match.params.repo_name} />} />

I passed the parameter from the link to the repo_name variable, so that I can then run it in the component, it works like this, it used to be through this.props.params.repo_name, but this design does not work, it was the same in the old router, I read the article here https://habrahabr .ru/post/329996/.
How can you please tell me the right way to pass parameters from the path to the component and then use them there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Spitsin, 2017-06-29
@Spitsin

If it's still relevant, then you can

<Route path="/repos/details/:repo_name"
render={(props) => <RepoDetails repo_name={props.match.params.repo_name} />} />

Or
<Route path="/repos/details/:repo_name"
render={(props) => <RepoDetails {...props} />} />

and in the RepoDetails component
const repoName = this.props.match.params.repo_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question