react-router 2.5 context undefiend replaceState deprecated
来源:互联网 发布:剑网三咩太捏脸数据 编辑:程序博客网 时间:2024/06/11 02:48
今天开始测试react-router 2.5 ,按网上的一般教程,一些用法都提示不建议使用了,还有context在子组件身上拿不到,一直提示undefined
例如:MyComp.contextTypes = {
router: React.PropTypes.func.isRequired
}
但是这样设置后会报错,也是醉了,
最后直接在最外层组件(APP)中赋值全局变量,window.gRouter=this.props.router,后面直接在子组件里直接操作这个gRouter就可以拿到router了,简单直接。
在react-router 2.5中不建议使用pushState/replaceState改成push/replace 参数也有变化
pushState(state, path, query)==》 push({path, query, state});
replaceState(state, path, query)==》replace({path, query, state});
var checkLogin=function(nextState, replace){
if(localStorage.login==undefined||localStorage.login ==’false’){ //模拟登陆
replace({path:’/’,query:{},state:{nextPathname:nextState.location.pathname}});//新的写法
//replaceState({nextPathname:nextState.location.pathname},’/’);//旧的写法
}
}
- react-router 2.5 context undefiend replaceState deprecated
- [react-router] `props.history` and `context.history` are deprecated. Please use `context.router`.
- React Router context.router 未定义错误
- React Router 4 this.context 未定义错误 history undefined
- ES6标准下react使用router跳转context.router未定义的解决
- react-router
- React Router
- React/Router
- react-router
- react-router
- react-router
- React-router
- react-router
- react-router
- react-router
- react-router
- React 之 react-router
- React Router--React Router4
- 网络状态代码
- HTML5 Canvas 图像动画的实现
- 1017: [JSOI2008]魔兽地图DotR
- Sublime Text 3使用SublimeLinter配置JS,CSS,HTML语法检查
- VR开发-VRTK基本设置
- react-router 2.5 context undefiend replaceState deprecated
- 数据库的索引和数据库查询
- 增量更新(制作差分包笔记)
- Unity3D在mac上使用VSCODE开发
- 备忘录模式(行为类)
- 今天12.7日,卖了氯霉素眼药水
- Codeforces Round #383 (Div. 2) B(打表)
- Serv-U FTP Server 中文版 11.0.0.4安装及使用说明
- I2C笔记