React导航 - 将堆栈路由器重置为初始路由,而不知道该路线是哪种路线



我正在使用带有多个嵌套路由器的选项卡路由器。

在一个可以在任何堆栈路由器中访问的屏幕中,我想进行一个将堆栈路由器(其中屏幕)重置为堆栈路由器的初始路由的操作。

例如:如果我在家庭堆栈路由器上,我希望将其重置为主屏幕,如果我在配置文件堆栈路由器上,我希望将其重置为配置文件屏幕。

有什么方法可以做到吗?

注意:我不与redux集成,redux集成是否会使此更容易?

我认为,最简单的方法可能是没有redux传递重定向屏幕 - 该堆栈的初始屏幕作为每个导航中的参数。

例如,

this.props.navigation.navigate('CommonScreen1', { initial: 'Home'});
this.props.navigation.navigate('CommonScreen2', { initial: 'Home'});
// in CommonScreen2 do the reset to the this.props.navigation.state.params.initial
this.props.navigation.navigate('CommonScreen1', { initial: 'Profile'});
this.props.navigation.navigate('CommonScreen2', { initial: 'Profile'});
// in CommonScreen2 do the reset to the this.props.navigation.state.params.initial

最新更新