📌  相关文章
📜  反应原生获取旧导航参数 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:10.401000             🧑  作者: Mango

代码示例1
The problem here is how navigation.navigate works. If you use it without
passing the key for the next screen, react-navigation won't match it with the 
screen that is already mounted hence mounting another one.

What you can observe here is exactly the case when the component was not yet 
unmounted but navigate doesn't know that and renders another instance of the 
same component.

You can prevent this by passing the key param into navigate function as follows:

navigation.navigate({name: 'ScreenB', key: 'ScreenB', params: { id: 1}})

navigation.navigate({name: 'ScreenB', key: 'ScreenB', params: { id: 2}})

Now StackNavigator can check if screen with the same key already exists and 
prevent it from mounting.