小编Nei*_*gan的帖子

反应路由器传递道具以路由组件

我正在尝试使用React Router将props从我的app.jsx传递到我的路由组件之一,但是出现以下错误

TypeError:无法读取未定义的属性“ acc”

这是我的app.jsx中的代码:

<Route exact path='/FileUpload' acc={this.state.account} ethAdd={this.state.ethAddress} component={FileUpload} />
Run Code Online (Sandbox Code Playgroud)

路由中的组件中的代码导致:

constructor(props) {
        super(props);
        this.setState({
            account: this.props.route.acc,
            ethAddress: this.props.route.ethAdd
        })
    }
Run Code Online (Sandbox Code Playgroud)

我从这里阅读其他解决方案并不能真正理解在响应路由器中传递道具的工作原理,有人可以帮助我理解我需要做什么吗?

reactjs react-router

2
推荐指数
2
解决办法
768
查看次数

标签 统计

react-router ×1

reactjs ×1