Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么不通过react路由器中的链接接收道具_Reactjs_React Router - Fatal编程技术网

Reactjs 为什么不通过react路由器中的链接接收道具

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

我的路线在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>
    );
  }
}
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);
返回(


); }
现在它可以工作了:)