Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  15] [ 3]  / answers: 1 / hits: 30053  / 8 Years ago, fri, july 8, 2016, 12:00:00

(Disclaimer: I am new to React and React-Router, so this may be obvious to someone with more familiarity)



I am creating a simple project with React-Router 2.5.2 with ES6 and I have a working solution but it feels like it may not be the React Router way. I have this Route:



<Route path=lists/:listId component={List}/>


and elsewhere I have a Link:



<Link to={`/lists/${props.list._id}`}>{props.list.name}</Link>


Is this the preferred way to compose a to attribute that passes dynamic content? Or am I fundamentally misunderstanding React Router?


More From » reactjs

 Answers
1

You are doing it right! :)



As you can see in the docs, this is the correct way to pass the to prop:



https://github.com/reactjs/react-router/blob/v2.5.2/docs/API.md#link



In previous React Router versions, there was a prop called params, where you would pass all your route params.



https://github.com/ReactTraining/react-router/blob/v0.13.6/doc/03%20Components/Link.md#params



But I think the React Router team decided to keep things simple, so you decide how you will build your routes. Also, using ES6 templates fit very well with that.


[#61460] Wednesday, July 6, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulissamirandah

Total Points: 493
Total Questions: 115
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
yulissamirandah questions
Fri, Jun 17, 22, 00:00, 2 Years ago
Wed, Aug 26, 20, 00:00, 4 Years ago
Tue, Jan 28, 20, 00:00, 4 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
;