简体   繁体   English

反应路由器道具未定义

[英]React Router Props Undefined

I'm using reactjs and react router in my web project, and I'm getting an error, here is the code. 我在我的web项目中使用reactjs并对路由器做出反应,我收到错误,这是代码。

App.js App.js

import React from 'react';
import {Router, Route, Link, browserHistory} from 'react-router'
import NewuserInfo from './NewUserInfomationComponent'

class AppComponent extends React.Component {
  render() {
    return (
      <Router history={browserHistory}>
        <Route path="/new/user/:pid" component={NewuserInfo}></Route>
      </Router>
    );
  }
}

NewUserInfomationComponent.js NewUserInfomationComponent.js

class NewUserInfomationComponent extends React.Component {

  constructor(){
    super(props)
    this.state = {
        ddiabetes: moment(),
        pid: this.props.params.pid,
        pmh : {},
        pmh_con: '',
        pmh_date: '',
        pmh_mng: ''
    }

}

In the following code when running I'm getting an error, 在以下代码运行时我收到错误,

Uncaught ReferenceError: props is not defined 未捕获的ReferenceError:未定义props

How can I fix this? 我怎样才能解决这个问题? Thanks 谢谢

You are not passing props to the constructor . 您没有将props传递给constructor constructor takes props as first argument and context as the second. constructorprops作为第一个参数,将context作为第二个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM