从父组件导航到特定组件(React Native Navigation)。

问题描述 投票:0回答:1

关于React Native Navigation的新手问题。

这是我的App.js。

import React, { Component } from 'react';

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

class App extends Component {

  constructor(props){
    super(props);
  }

  myFunction(){
    /*
      -------------------------------------------
      Navigate from Component1 to Component2 (???)
      -------------------------------------------
    */
  }

  render(){
    return(
          <Stack.Navigator>
              <Stack.Screen name="Component1" component={Component1} />
              <Stack.Screen name="Component2" component={Component2} />
          </Stack.Navigator>
    );
  }

}

export default App

在同一个类中,在myFunction中,我想导航到的是 构成部分2. 怎么做呢?

我找到的所有指南,都解释了如何在里面做。组成部分1,使用导航道具。我需要从父体做起。

react-native react-native-navigation
1个回答
1
投票

你可以试试这个

this.props.navigation.navigate("Component2")
© www.soinside.com 2019 - 2024. All rights reserved.