怎么做?例如,我发现了这个:
<Link to={{pathname: "/dialog", state: { detail: message }}}>
text
</Link>
但如果我想显示 this.props.location.state ,请写 undefined 。
答案 0 :(得分:0)
传递参数
Configure your route path to accept named parameters (:id):
<Route path='/route/:id' exact component={MyComponent} />
Then you can pass URL parameters such as IDs in your link to:
<Link to={`route/foo`}>My route</Link>
You can access the parameter within your component via the match object:
const {id} = props.match.params
console.log(id) // "foo"