gpt4 book ai didi

javascript - 在 React 中获取路由参数

转载 作者:行者123 更新时间:2023-12-05 05:43:29 30 4
gpt4 key购买 nike

<分区>

<Route path="chats/:id" element={<Chat />} />
import React from "react";

export default class Chat extends React.Component {
render() {
return (
<>
{this.props.match.params.id}
</>
)
}
}

如果我使用它,我只会得到一个白色站点和以下错误:

Chat.js:6 Uncaught TypeError: Cannot read properties of undefined (reading 'params')
at Chat.render (Chat.js:6:1)
at finishClassComponent (react-dom.development.js:20487:1)
at updateClassComponent (react-dom.development.js:20433:1)
at beginWork (react-dom.development.js:22366:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4157:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4206:1)
at invokeGuardedCallback (react-dom.development.js:4270:1)
at beginWork$1 (react-dom.development.js:27243:1)
at performUnitOfWork (react-dom.development.js:26392:1)
at workLoopSync (react-dom.development.js:26303:1)

我怎样才能让它发挥作用?没有教程或谷歌搜索有效。

(我使用 react-router-dom v6)

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com