简体   繁体   中英

React navigator not moving between screens

My app closes when I press the switch screen button. I don't see any error output. I did a version check and there was no problem.

The function I wrote for the button works

Router.js

import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import First from "./First";
import Second from "./Second";
const Stack = createNativeStackNavigator();

const Router = () =>{
    return(
        <NavigationContainer>
            <Stack.Navigator initialRouteName="First">
                <Stack.Screen name="First" component={ First }/>
                <Stack.Screen name="Second" component={ Second }/>
            </Stack.Navigator>
        </NavigationContainer>
    );
}

export default Router;

First.js

import React from 'react';
import {View,Text,Button} from 'react-native';


const First = ( props ) =>{
    const gotoSecond = () => {
        console.log("First");
        props.navigation.navigate("Second");
        console.log("second")
    }
    return (
        <View>
            <Text>Hello First Page!</Text>
            <Button title="Go SecondPage!" onPress={gotoSecond}/>
        </View>
    );

};

export default First;

Second.js

import React from 'react';
import {View,Text} from 'react-native';

const Second = () =>{
    return (
        <View>
            <Text>Hello Second Page!</Text>
        </View>
    );

};

export default Second;

OS:Android, Emulator:Genymotion.

现在我使用 ADV 而不是 Genymotion,问题解决了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM