在我的Web项目中,我尝试访问路由参数。
定义路线:
<Route path="/meeting/:id">
<MeetingDetails />
</Route>
组件已加载,但由于this.props.match
未定义,我无法访问路由参数。如何访问路线参数id
?
import React from "react";
export default class MeetingDetails extends React.Component {
constructor(props) {
super(props);
console.log(this.props.match);
}
render() {
return (
<div>
Details
</div>
);
}
}
你应该设置component
的道具<Route>
给你的<MeetingDetails>
组件:
<Route path="/meeting/:id" component={MeetingDetails}/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句