Is it possible to pass an object via Link component in react-router?
Something like:
Click <
Using react-roter-dom ver 5.1.2 and es6
I solved the problem like this first I store it in the search part of Link to object meaning it is part of the url and supports a bookmark etc.
< Link to={{
pathname: `${match.url}/${dogName}`,
search: `choosenDog=${JSON.stringify({ ...dog })}` //dog is the object to pass along
}
} >
And then on the link we goto I get hold of it like this
const query = useQuery();
const dogString = query.get('choosenDog');
const dogObject = JSON.parse(dogString);