我的路线在App.js
<Route
path="/BlogEdit/:blogId"
handler={BlogEdit}
component = {() => <BlogEdit editBlog={this.editBlog}/>}
/>
我的链接位于blog.js
<Link to={`/BlogEdit/${this.blogId}`}>
<a className="waves-effect waves-light btn">Edit</a>
</Link>
我要访问blogId的组件是
render() {
console.log(this.props.match.params.blogId); // this comes out undefined
return (
<div className = "Editor">
<br/><br/>
</div>
);
}
}
我该怎么办?
答案 0 :(得分:0)
我终于改变了我的路线:
<Route
path="/BlogEdit/:blogId"
render={props => <BlogEdit {...props} editBlog={this.editBlog} />}
/>
我的链接:
<Link to={`/BlogEdit/${this.blogId}`}
className="waves-effect waves-light btn">Edit
</Link>
我的组件:
render() {
const { editorState } = this.state;
const {match: { params } } = this.props;
const { blogId } = params;
console.log(blogId);
return (
<div className = "Editor">
<br/><br/>
);
}
它现在有效:)