在render方法中用内部组件反应js,我把控制台日志this.props获取一个空对象值!这是我的代码,
import React, { Component } from 'react';
import { Router, Route, Link, IndexRoute, hashHistory, browserHistory } from 'react-router';
import Home from './home';
import About from './about';
class App extends React.Component {
constructor(){
super();
}
render() {
console.log(this.props)
return (
<div>
Hi
</div>
);
}
}
export default App
答案 0 :(得分:0)
您可以使用withRouter
高阶组件:
import React, { Component } from 'react';
import { Router, Route, Link, IndexRoute, hashHistory, browserHistory, withRouter } from 'react-router';
import Home from './home';
import About from './about';
class App extends React.Component {
constructor(){
super();
}
render() {
console.log(this.props)
return (
<div>
Hi
</div>
);
}
}
export default withRouter(App)