Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
App is crashing when I try to navigate between screens - Expo

My App is crashing with no error logs on the console when I'm trying to navigate between screens based on the onAuthStateChanged() method.

Navigation Packages used : "@react-navigation/native": "^6.0.6", "@react-navigation/stack": "^6.0.11",

can somebody help me?

Loading.js

import React, { useEffect } from "react";
import firebase from '../config/firebase';
import { View, StyleSheet, ActivityIndicator, StatusBar } from "react-native";
import { CommonActions } from '@react-navigation/native';



export default function Loading({ navigation }) {
  StatusBar.setBarStyle('dark-content');
  
  useEffect(() => {
    console.log('from useEffect');
    firebase.auth().onAuthStateChanged((user)=>{
      if(user!=null ){
        navigation.dispatch(
          CommonActions.reset({
            index: 1,
            routes: [
              { name: 'HomeRoute' },
            ],
          })
        )
        // navigation.navigate('HomeRoute')
      }else{
        navigation.dispatch(
          CommonActions.reset({
            index: 1,
            routes: [
              { name: 'LoginRoute' },
            ],
          })
        )
        // navigation.navigate('LoginRoute');
      }
    })
  })
  
  return (
    <View style={styles.container}>
      <ActivityIndicator size='large' color='#333333' style={styles.indicator}  ></ActivityIndicator>
    </View>
  );
}

App.JS

import Login from './screens/Login';
import Home from './screens/Home';
import Loading from './screens/Loading';
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";

const Stack = createStackNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName='LoadingRoute' screenOptions={{headerShown: false}}>
        <Stack.Screen name='LoginRoute' component={Login} />
        <Stack.Screen name='HomeRoute' component={Home} />
        <Stack.Screen name='LoadingRoute' component={Loading} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You got dispatch action a bit off.

You are passing in an index: 1 which is telling the navigation to focus the route at index 1 once the navigation is finished.

The problem is you have only a single route inside routes, so you should tell the navigation to focus route at index 0 like so

navigation.dispatch(
  CommonActions.reset({
    index: 0,
    routes: [{ name: "LoginRoute" }],
  })
);

I would also highly advise reading the official docs on how to set up your authentication flow with react-navigation.

TLDR: What you should do basically is conditionally render the routes based on the user login state and let react-navigation handle the rest for you.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda