我正在尝试使用 Link 传递状态
<Link to={{ pathname: `/contact/:${contact.id}`, state: { contact }, }}>
这就是我想使用链接传递此状态的地方,但我的位置未定义
function ContactDetails({ location }) {
console.log(location);
const { name, email } = location.state.contact;}
这是我的路线:
<Route path='/contact/:id' element={<ContactDetails />}/>
回答1
刚刚得到了答案,我这样做了,它解决了我的问题
<Link to={`/contact/:${contact.id}`} state={{ contact }}>