react-router-tutorial icon indicating copy to clipboard operation
react-router-tutorial copied to clipboard

How to pass params by Link ?

Open eromoe opened this issue 8 years ago • 6 comments
trafficstars

Hi,

I know I can pass params by Route like

<Route path="/corpus/:corpusId/tag" component={TagPage} tags={tags}  />}/>

But that require set component , and component must be child of current page. That is inconvenient.

I'd like to use Link like

<Link path="/corpus/:corpusId/tag" tags={tags}  />}/>

Automatically pass tags to certain component.

eromoe avatar Sep 18 '17 03:09 eromoe

You can pass an object to the Link:

<Link to={{
  pathname: '/courses',
  search: '?sort=name',
  hash: '#the-hash',
  state: { fromDashboard: true }
}}/>

https://github.com/ReactTraining/react-router/blob/dc10832d23f9ab673891805c9c866b90d1ef1ed6/packages/react-router-dom/docs/api/Link.md#to-object

luish avatar Mar 16 '18 13:03 luish

Will this work for you?

<Link to={/corpus/${corpusId}/tag}>

Assuming of course the "corpusId" you wanted exists already by the time you make that Link

Well that is just ruining my formatting. basically there are backticks ` around the "/corpus.../tag"

MiniRaccoonDog avatar Nov 28 '18 18:11 MiniRaccoonDog

Why are people down voting @luish 's answer?

That's the correct answer according to the docs..

fonziemedia avatar Mar 01 '19 08:03 fonziemedia

Why are people down voting @luish 's answer?

That's the correct answer according to the docs..

I.. think its because its straight copy-pasted from the react-router docs and isn't tailored to the asker's original question? Which isn't as ideal because, in theory the asker has already seen those docs and didn't quite follow how to get the iteration they desired. People are looking for a little more than C&P, they want a tailored response

MiniRaccoonDog avatar Mar 01 '19 15:03 MiniRaccoonDog

Well, my answer replied to the question in the title "How to pass params by Link?" Anyway this is an old issue that hopefully got resolved. 🙂

luish avatar Mar 06 '19 16:03 luish

I would like to know if there's a solution to past params "invisibles" in the query or if the params HAVE to be visibles ?

GOFFARTSylvain avatar Mar 21 '19 15:03 GOFFARTSylvain