kenberkeley / react-demo

React 示例项目 · 简易留言板。本项目拥有完善的文档说明与注释,让您快速上手 React 开发 SPA。Webpack / ES6 + Babel / Redux / React Router —— An Excellent React Starter,可能是东半球最佳的 React Starter,基于 Vue Cli 二次开发
1.91k stars 537 forks source link

关于componentWillReceiveProps 无限循环问题 #29

Closed Measy closed 7 years ago

Measy commented 7 years ago

handleIllegal() { //使用setTimeout防止阻塞跳转 setTimeout(() => alert('非法访问')) location.replace('/msg')

    // 为什么不使用如下代码跳转?
    // this.context.router.replace('/msg')
    // 因为会触发 componentWillReceiveProps 无限循环
}

请问一下博主为什么this.context.router.replace('/msg')为造成无线循环

kenberkeley commented 7 years ago

试一下就知道了呗ㄟ( ▔, ▔ )ㄏ

Measy commented 7 years ago

http://stackoverflow.com/questions/36189775/infinite-loop-when-dispatching-in-componentwillreceiveprops 感谢博主详细的注释