0

How I am calling Link

<Link to={{ pathname: row.route, partname: "test" }} className='nav-links'>
  <Button variant="contained">Choose {row.name}</Button>
</Link>

How I am trying to access it:

export default function Products() {
    const location = useLocation()
    const partname = location.state?.partname

    console.log("partname: " + partname)

But partname is always null even though I am passing in partname = "test".

I am pretty new to React and it seems like this is the standard way to pass in arguments to functions components. Thanks in advance! \

Using: "react-router-dom": "^6.0.1",

Ayeemba
  • 37
  • 4
  • Does this answer your question? [How to pass data from a page to another page using react router](https://stackoverflow.com/questions/59701050/how-to-pass-data-from-a-page-to-another-page-using-react-router) – Drew Reese Mar 21 '22 at 02:00

1 Answers1

0

Hmm it seems like this works for v6:

                    <Link to={row.route} state={{partname: "test"}}><Button variant="contained">Choose {row.name}</Button></Link>
Ayeemba
  • 37
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 20 '22 at 13:54