Resetting the navigation stack for the home screen (React Navigation and React Native)

前端 未结 13 2385
终归单人心
终归单人心 2020-11-29 23:49

I\'ve got a problem with the navigation of React Navigation and React Native. It is about resetting navigation and returning to the home screen.

I\'ve build a StackN

13条回答
  •  醉梦人生
    2020-11-30 00:07

    In React Navigation Versions 5.x

    You can use StackActions.replace in this version

    import { StackActions } from '@react-navigation/native';
    
    
    navigation.dispatch(
        StackActions.replace('Home', { test: 'Test Params' })
    )
    

    Full Example: (Available in Snack)

    import * as React from 'react';
    import { View, Button, Text } from 'react-native';
    import { NavigationContainer, StackActions } from '@react-navigation/native';
    import { createStackNavigator } from '@react-navigation/stack';
    
    function SplashScreen({ navigation }) {
      return (
        
          SPLASH SCREEN!
          

提交回复
热议问题