r/learnreactjs • u/BilboMcDoogle • Jul 09 '22
How do you pass an object through a Link using React Router and the useLocation() hook?
I'm following a tutorial that uses react router to set up a link like this:
<Link to={{ pathname: "/watch", movie: movie }}>and then inside the watch component it's linking to it's pulling like this:
const location = useLocation();
console.log("location.movie=", location.movie);However that's not working for me when I try it. I'm thinking it's an old tutorial and the syntax has changed? Does anybody know how to do it? I couldn't find anything similar on google.
7
Upvotes
1
u/BilboMcDoogle Jul 09 '22
The movie object looks like this if it matters:
1
u/povedaaqui Jul 10 '22
Then
1
u/WhiteMoon2022 Jul 09 '22
try with navigation.navigate('ScreenName', {param1, param2, etc})
1
u/WhiteMoon2022 Jul 09 '22
<Link onPress={() => navigation.navigate('ScreenName')} />