【发布时间】:2021-11-06 07:58:11
【问题描述】:
如何在功能组件中访问这个 match.chatroomId ?
我使用 history.replace 重定向到组件
onClick = {() => history.replace(`/chat/${match.chatroomId}`)}
【问题讨论】:
标签: javascript reactjs react-redux react-hooks react-router
如何在功能组件中访问这个 match.chatroomId ?
我使用 history.replace 重定向到组件
onClick = {() => history.replace(`/chat/${match.chatroomId}`)}
【问题讨论】:
标签: javascript reactjs react-redux react-hooks react-router
使用 react hook useParams() 这是 url - http://localhost:8000/personal/1。
所以在这种情况下,use const { id } = useParams()
现在,如果您执行 console.log(id) ,它将为您提供网址的确切 ID。在这种情况下,它会给你 1。
useParams() 从 url 中提取 id 并让我们使用它。
谢谢。
【讨论】: