I am using @react-navigation/native upgraded current version but i am trying to reset the index 0 using the CommonAction.reset() not working
scenerio: I am in the login page once i loggined the splash screen in my root stack initially showing 3 seconds delay then navigate tot eh dashboard my question is why the splash screen is showing initially i already tried lot of things to reset the initialScreen while login or logout not working
type SplashScreenProp = NativeStackNavigationProp<RootStackParamList, 'Splash'>;
const Splash = () => {
const navigation = useNavigation<SplashScreenProp>();
navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [{ name: 'TabRoot' }],
})
);
const RootNavigator = () => {
return (
<HeaderButtonsProvider stackType="native">
<RootStack.Navigator
screenOptions={{
headerBackTitleVisible: false,
headerTitleStyle: screenOptions,
headerTitleAlign: 'center',
}}>
<RootStack.Screen name="Splash" component={Splash} options={{ title: '', headerShown: false }} />
<RootStack.Screen name="Login" component={Login} options={{ title: '', headerShown: false, animation: 'fade' }} />
<RootStack.Screen name="TabRoot" component={TabNavis} options={{ title: '', headerShown: false }} />
<RootStack.Screen
name="Settings"
component={Settings}
options={{
title: 'Settings',
headerTitleStyle: screenOptions,
}}
/>
2
Answers
You can directly reset to particular screen by writing below code:
You can solve this issue using conditional rendering.
For example, like this:
Alternatively, you can display the splash screen in a modal to avoid using it in the navigation since it’s only needed during the project initialization.