The prop `history` is marked as required in `Router` …
The prop `history` is marked as required in `Router`, but its value is `undefined`. in Router
解决办法:
出现这个报错是因为我用npm 安装的是react-router v4,react-router v4不再使用<Router history={hashHistory}>
这种方式定义history 实现类型。而是直接通过组件如BrowserRouter,HashRouter等
|
|
A ‘Router’ may have only one child element
react-router v4 在
解决办法:
用div 或者Switch 包裹所有Route
webpack 配置问题
v4 中引入<BrowserRouter>
组件, 而BrowserRouter使用的是HTML5 的history api, 在使用webpack-dev-server时会遇到
GET http://localhost:8080/xxx/xxx 404 (Not Found)
解决办法:
webpack.config.js中加入
然后将index.html中的bundle.js改为/bundle.js
|
|
参考:https://stackoverflow.com/questions/43209666/react-router-v4-cannot-get-url
question
https://segmentfault.com/q/1010000010432084?_ea=2287891
静态路由和动态路由
https://reacttraining.com/react-router/web/guides/philosophy
react-router 传参
使用/xxx/:someparam 的形式书写Route 的path属性,如:
然后Link 的to属相加上参数即可,如:
|
|
最后在ComponentFooter中通过this.props.match.params访问,如:
|
|
完整代码
|
|