【发布时间】:2017-10-04 23:26:52
【问题描述】:
我正在用电子创建我的第一个反应应用程序(也是我的第一个电子应用程序)。我有两条路线,需要从一条导航到另一条。为此,我使用以下代码:
根
ReactDOM.render(
<Router history={browserHistory}>
<App />
</Router>,
document.getElementById('root')
);
应用
class App extends React.Component {
constructor() {
super();
}
render() {
return (
<div className="app-master">
<Switch>
<Route path='/city' component={CityList}/>
<Route path='/' component={SplashScreen}/>
</Switch>
</div>
)
}
}
页面
import { browserHistory } from 'react-router';
...
browserHistory.push('/city');
这一行给出错误,
TypeError: Cannot read property 'push' of undefined
我在网上搜索了可能的解决方案,但找不到!关于 SO 也有很多类似的问题,但没有一个对我有用:(
【问题讨论】:
-
因为你在
App构造函数中没有做任何特别的事情,这部分是不必要的:`constructor() { super(); } `
标签: javascript reactjs react-router electron