react router mobile 页面跳转多次出现卡顿-解决

最近在项目中遇到的问题和大家分享。以免更多的人踩坑

页面需求如下图:


    坑:当页面下一题点击次数过多时,页面会变得卡顿,甚至mobile browser 崩溃、闪退

页面路径:XXXXXX/1、XXXX/2、XXXX/3

当跳转到下一个界面时 history.push(`${url}/${id}`,{OBJECT})

遇到问题:当页面下一题点击次数过多时,页面会变得越来越卡顿卡顿,甚至mobile browser 崩溃、闪退


我google了大量的资料,最后发现是react router的原因

解决方案:http://reacttraining.cn/web/api/Link/replace-bool

push 会将历史保存在堆栈中

replace 则会清除

将push改成replace 完美解决!

愿react的盆友们碾压各种坑!

你可能感兴趣的:(react router mobile 页面跳转多次出现卡顿-解决)