Login React Native + Firebase error using "Switchnavigator"

Asked

Viewed 104 times

0

Error (Undefined is not a Function (near '...(0, _reactNavigation.Switchnavigator)...')) when compiling application.

I need that when logging in is directed to the screen "Main".

import React from 'react'
import { StyleSheet, Platform, Image, Text, View } from 'react-native'
import { SwitchNavigator } from 'react-navigation'

// import the different screens
import Loading from './Loading'
import SignUp from './SignUp'
import Login from './Login'
import Main from './Main'

// create our app's navigation stack
const App = SwitchNavigator(
  {
    Loading,
    SignUp,
    Login,
    Main
  },
  {
    initialRouteName: 'Loading'
  }
)

export default App
  • you want it to be redirected from where? where is the code you are trying to redirect? which function is calling?

1 answer

0

First you have to use the createSwitchNavigator and not SwitchNavigator according to the Navigator switch you have to use combining 2 Navigators + switch to make flows from Tools below example of how to use it

import { createSwitchNavigator, createStackNavigator } from 'react-navigation';
import Loading from './Loading'
import SignUp from './SignUp'
import Login from './Login'
import Main from './Main'

const NaoLogado = createStackNavigator({
  Login,
  SignUp,
  Loading,
}, {
  initialRouteName: 'Loading',
})

const Logado = createStackNavigator({
  Main
}, {
  initialRouteName: 'Main',
});

const criarNavigator = (condicao) => createSwitchNavigator({
  NaoLogado,
  Logado
}, {
  initialRouteName: condicao ? 'Logado' : 'NaoLogado'
});

export default criarNavigator
// No componente tu pode fazer assim

render() {
  const Router = criarNavigator(valor);

  return <Router />
}

If Voce is using version 3.0 of React-navigation you will have to use it this way using the createAppContainer of the Act-navigation:

const criarNavigator = (condicao) => 
  createAppContainer(
    createSwitchNavigator(
      ...
    ),
  )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.