📅  最后修改于: 2022-03-11 15:02:10.401000             🧑  作者: Mango
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.