在 route 我设置了props
:
<Route path="/getFilePage" exact component={GetFilePage} CourseName={props.CourseName} />
在主页中我编写了以下重定向代码:
return <Redirect to={{
pathname: '/getFilePage',
CourseName:"C++"
}}/>
在 GetFilePage
组件中,我在 componentDidMount console.log(this.props.location.CourseName)
中编写,但未定义
最佳答案
语法错误。尝试如下:
return <Redirect to={{
pathname: '/getFilePage',
state:{CourseName:"C++"}
}}/>
并采用如下所示的参数:
this.props.location.state.CourseName
关于javascript - 如何重定向到另一个页面并在reactjs中使用props,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58875192/