
react-router
朱知知
想做一本你读了一遍又一遍,仍不舍得放下的书
展开
-
react-router中this.props.history为undefined?解决报错Cannot read property ‘push‘ of undefined
在使用this.props.history.push(’/xxx’)的时候遇到这个报错:大概率原因:只有用了Route组件,才会在子组件中注入route props(即 history, location, match)详见官方文档route props所以下面这个例子中,Header 和 Footer组件中,this.props.history === undefined,在ModuleA 和 ModuleB中,this.props.history就有值(因为有< Route >原创 2020-11-02 20:10:54 · 6030 阅读 · 1 评论 -
React-router - 如何在url中带参数?在url中带参数的几种方法
方法一:/myurl?id=1&name=chris通过location.search基本方法1.react-route配置:const route = { path: '/myurl', component: myUrl,};<Route path={route.path} component={route.component} />2.跳转url时携带参数的方法:const id = 1; const name = 'chris';this.pr原创 2020-10-20 21:00:59 · 20751 阅读 · 3 评论