【发布时间】:2019-03-17 06:21:54
【问题描述】:
我通过在命令提示符窗口中运行以下代码 sn-p 在我的项目上安装了react-router:
npm install react-router
我发现react-router安装成功,因为安装没有错误,而且输出是:
- 反应路由器@4.3.1 在 19.53 秒内更新了 1 个包
基于tutorial,我将我的Index.js 设置为如下代码:
ReactDOM.render((
<Router history = {browserHistory}>
<Route path = "/" component = {App}>
<IndexRoute component = {Home} />
<Route path = "home" component = {Home} />
<Route path = "about" component = {About} />
<Route path = "contact" component = {Contact} />
</Route>
</Router>
), document.getElementById('app'))
现在当我想编译/构建我的应用程序时,会出现以下错误:
./src/index.js
Line 14: 'Router' is not defined react/jsx-no-undef
Line 14: 'browserHistory' is not defined no-undef
Line 15: 'Route' is not defined react/jsx-no-undef
Line 16: 'IndexRoute' is not defined react/jsx-no-undef
Line 17: 'Route' is not defined react/jsx-no-undef
Line 18: 'Route' is not defined react/jsx-no-undef
Line 19: 'Route' is not defined react/jsx-no-undef
我知道编译器找不到路由类,我已经在 google 和这个社区上搜索过我的问题之类的问题,但实际上我的搜索结果没有帮助。感谢您的回复。
【问题讨论】:
标签: reactjs routing react-router react-router-v4 react-router-dom