当我在react native中导航到新页面时如何强制卸载组件? [英] How do I force a component to unmount when I navigate to a new page in react native?

查看:348
本文介绍了当我在react native中导航到新页面时如何强制卸载组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确保在导航到新页面时会触发生命周期方法ComponentWillUnmount.我发现了这条帖子,但这没有似乎没有提及有关导航到新页面的任何信息.我还发现了这条帖子,但是我正在使用反应导航.另外,我没有使用pop/push.我只是使用this.props.navigation.navigate('SomePage')进入下一页

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

推荐答案

您可以使用this.props.navigation.replace('routName'); 它将完成您的工作.

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

这篇关于当我在react native中导航到新页面时如何强制卸载组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆