代码之家  ›  专栏  ›  技术社区  ›  Gowthaman

有没有方法可以动态地将新路由添加到React native堆栈导航中

  •  2
  • Gowthaman  · 技术社区  · 7 年前

    我们正在构建一个应用程序,其中使用React native stack Navigation,

    基于webapi调用,我想向现有堆栈注入一个新的路由,它应该能够返回到以前的屏幕

    有什么办法可以达到这个目的吗。?

    3 回复  |  直到 7 年前
        1
  •  1
  •   Isaac    7 年前

    引自 https://reactnavigation.org/docs/en/navigating.html

    如果我们打电话这个。道具。导航。使用尚未在堆栈导航器上定义的路由名称导航,则不会发生任何操作。换句话说,我们只能导航到在堆栈导航器上定义的路由,我们不能导航到任意组件。

        2
  •  0
  •   VolkanSahin45    7 年前

        3
  •  0
  •   Majid Amiri    7 年前

    index 是要在新上导航的路由的索引 actions 'NewRoute' 而它 指数 1 )

    import {StackActions, NavigationActions} from "react-navigation"
    
    class Example extends Component {
    
      // ... Some other methods
    
      navigate = (id) => {
        const resetAction = StackActions.reset({
          index: 1,
          actions: [
            NavigationActions.navigate({ routeName: 'Home' }),
            NavigationActions.navigate({ routeName: 'NewRoute', params: { id, ...otherParams } }),
          ],
        });
        this.props.navigation.dispatch(resetAction);
      }
    
      render() {
        return (
          <View>
            <TouchableOpacity onPress={() => this.navigate()}>
              <Text>Go to New Route</Text>
            </TouchableOpacity>
          </View>
        );
      }
    }
    
    推荐文章