在StackNavigators(嵌套堆栈)之间导航时动态更改initialRouteName

时间:2019-07-12 10:52:38

标签: javascript android ios react-native react-navigation

我在一个StackNavigator中使用了多个StackNavigator。我想导航到堆栈中的特定屏幕,而不是导航时定义的initialRouteName。

我已经尝试用navigation.dispatch()进行StackActions / NavigationActions。但是无法解决问题。

(() => {
  var add = (function outerAdd() {
    var arr = [];
    return function innerAdd(item) {
      arr.push(item);
    }
  })();

  // here, the "arr" variable will still exist because it can be seen by the `add` function
  add(5);
  add(3);
  add(5);
})();
// here, since the `add` function is no longer referencable, and nothing else can reference the `arr`,
// the `arr` will get garbage collected

我想从firstStack-firstScreen导航到secondStack-FourthScreen。

1 个答案:

答案 0 :(得分:0)

在您的firstScreen组件中,使用以下代码导航到您的fourthScreen组件:

this.props.navigation.navigate('fourthScreen', {}, NavigationActions.navigate({ routeName: 'fourthScreen' }));