Reactjs 为什么不通过react路由器中的链接接收道具
我的路线在App.js中Reactjs 为什么不通过react路由器中的链接接收道具,reactjs,react-router,Reactjs,React Router,我的路线在App.js中 <Route path="/BlogEdit/:blogId" handler={BlogEdit} component = {() => <BlogEdit editBlog={this.editBlog}/>} /> } /> 我的链接在blog.js中 <Link to={`/BlogEdit/${this.blogId}`}> <a c
<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>
);
}
}
render(){
console.log(this.props.match.params.blogId);//这是未定义的
返回(
);
}
}
我该怎么办?我终于将路线改为:
<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/>
);
}
render(){
const{editorState}=this.state;
const{match:{params}}=this.props;
const{blogId}=params;
log(blogId);
返回(
);
}
现在它可以工作了:)