'how to pass props through a Link from react-router-dom?

I'm trying to pass state using Link

<Link to={{ pathname: `/contact/:${contact.id}`, state: { contact }, }}>            
                

And this is where I want to get this state passed using link but I'm getting location undefined

function ContactDetails({ location }) {
console.log(location);
const { name, email } = location.state.contact;}

And this is my Route:

<Route path='/contact/:id' element={<ContactDetails />}/>


Solution 1:[1]

Just got an answer for this I did this and it resolve my issue

<Link to={`/contact/:${contact.id}`} state={{ contact }}>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sunil