react router4 官网中文文档地址:https://react-router.docschina.org
下载包:
npm install react-router-dom --save
文档原文:在web应用程序中使用的所有组件都应该从react-router-dom中取
react-router应用程序的核心应该是一个router组件,对于web项目,react-router-dom提供了<BrowserRouter>和<HashRouter>路由。这两个路由都会为你创建一个专门的history对象。一般来说,如果你有一个相应请求的服务器,则你应该使用<BrowserRouter>,如果你使用的是静态文件的服务器,则应该使用<BrowserRouter>。
文档中还提到了一个<MemoryRouter>,文档原文:<Router>能在内存中保存你的URL的历史记录(并不会对地址栏进行读写)。很适合在测试环境和非浏览器环境中使用,例如ReactNative。
我尝试直接用<Router>...</Router>时提示错误,history是必须的
Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
in Router (created by App)
in App
由于Browser