How do I force a component to unmount when I navig

2020-04-08 14:10发布

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

2条回答
【Aperson】
2楼-- · 2020-04-08 14:49

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.

查看更多
男人必须洒脱
3楼-- · 2020-04-08 15:02

You can use this.props.navigation.replace('routName'); It will do your job.

查看更多
登录 后发表回答