问题
I want to make sure the lifecycle method ComponentWillUnmount fires when I navigate to a new page. I found this post, but that doesn't seem to mention anything about navigating to a new page. I also found this post but I'm using react-navigation. In addition, I'm not using pop/push. I'm simply using this.props.navigation.navigate('SomePage') to get to the next page
回答1:
You can use this.props.navigation.replace('routName');
It will do your job.
回答2:
Checkout React Navigation
's ways to handle a component's lifecycle event in their docs here
TL;DR, you can checkout React Navigation's navigation lifecycle event to perform actions when you switch screens. Hope it helps.
来源:https://stackoverflow.com/questions/55018589/how-do-i-force-a-component-to-unmount-when-i-navigate-to-a-new-page-in-react-nat