2

I'm using react-router-dom Link to direct the user to another endpoint. I'd like to be able to send params, such as the current components props or local state.

I've tried this...

<Link to='/meals/new' params='test'>Add Food</Link>

The props show up empty... screen shot of props

I've had minor success when I tried to pass extra params like this..

const newTo = {
    pathname: '/meals/new',
    params: 'Test',
    title: this.state.title
  }

Using that style, I include it with the Link like this..

<Link to={newTo}</Link>

In that particular case, I get the object within my Location key. However, I'm defining the const outside of my class, and don't know how to grab local state if I do it this way.

Is there a way to get my first method working?

Thanks!

peterchic
  • 407
  • 1
  • 4
  • 11
  • I think this post might answer your question: https://stackoverflow.com/questions/30115324/pass-props-in-link-react-router – Sebastian K. Feb 01 '18 at 14:53
  • `Add Food` ?? – soupette Feb 01 '18 at 15:45
  • @soupette Are you able to pass props this way, or local state? – peterchic Feb 01 '18 at 16:54
  • @SebastianK. Thanks for the reply! That is where I found the second method I listed above. Can't seem to find a way to make this work : / – peterchic Feb 01 '18 at 17:03
  • Here is an example https://github.com/strapi/strapi/blob/master/packages/strapi-admin/admin/src/components/LeftMenuLink/index.js – soupette Feb 01 '18 at 17:52
  • @peterchic okay, I think the problem is that you're defining the const outside of your class. So if you define it inside it works? Maybe you can export the const and import it in your class and pass it to the Link? – Sebastian K. Feb 02 '18 at 10:35

0 Answers0