Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

How to pass params by Link ? #327

Open
eromoe opened this issue Sep 18, 2017 · 6 comments
Open

How to pass params by Link ? #327

eromoe opened this issue Sep 18, 2017 · 6 comments

Comments

@eromoe
Copy link

eromoe commented Sep 18, 2017

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.

@luish
Copy link

luish commented Mar 16, 2018

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

@MiniRaccoonDog
Copy link

MiniRaccoonDog commented Nov 28, 2018

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"

@fonziemedia
Copy link

Why are people down voting @luish 's answer?

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

@MiniRaccoonDog
Copy link

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

@luish
Copy link

luish commented Mar 6, 2019

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. 🙂

@GOFFARTSylvain
Copy link

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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants