Cannot navigate to same route with different params · Issue #2882 · react

您所在的位置:网站首页 最强头像迪迦奥特曼 Cannot navigate to same route with different params · Issue #2882 · react

Cannot navigate to same route with different params · Issue #2882 · react

2023-04-24 00:23| 来源: 网络整理| 查看: 265

@sungsong88 Yeah, it really depends on your setup. The navigate function does provide some benefits. Say I have 3 screens A, B, and C. I start on screen A and navigate to screen B, then to screen C. My navigation route history stack now looks like [A, B, C].

Here is where it gets tricky. If I navigate to screen B at this point, react-navigation will see that I just came from screen B, and pop the last screen (i.e. screen C) from the stack so that my route history now looks like [A, B]. If screen B doesn't take any params and will always look the same regardless of how you navigate to it, this is probably what we want. The benefit is that B has already been rendered, and by essentially just navigating back, performance is improved and our route history is cleaner.

On the other hand, if my route history is [A, B, C], and I push to B, then my route history will become [A, B, C, B]. We do more render work, but we can ensure that the first B is different than the second B.

In our case, this was important because we had Profile component that took an id in params. Without using push, there was no guarantee that you'd see the correct profile!

Hopefully that didn't make it more confusing 😆



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3