安装'react-router'会产生不一致的版本

时间:2017-04-06 16:36:12

标签: reactjs react-router react-router-v4

我通过这样做安装了react路由器:

  

npm install react-router

我安装的内容与我在互联网上阅读的几乎所有教程都不一致。一个例子:https://css-tricks.com/learning-react-router/

首先,它缺少 IndexRoute IndexRoute 在哪里?我似乎无法让我的任何例子都有效。

1 个答案:

答案 0 :(得分:2)

When you install a package like

npm install react-router

It installs the latest package that is available on the npm repository. If you see the package.json, you will have the version the React router to be 4.x.x which doesn't have IndexRoute

You should install v3.x.x

To do that, remove the entry for react-router from your package.json and delete the node_modules.

Now run

npm install 

followed by

npm install -S react-router@3.x.x

See the react-router v4.0.0 Docs