Navigate to root screen from nested stack navigator

后端 未结 4 1142
迷失自我
迷失自我 2021-01-18 21:59

i am new to react and trying to learn it by myself , i am facing problem in navigating user back to root screen from nested stck navigator screen .

Here is some of m

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 22:08

    (React Navigation 5.x) I had the problem of conditionally rendering the Screens like the example in "https://reactnavigation.org/docs/en/auth-flow.html" As I understand, meant that the Stack navigators were not "rendered" and thus are not able to find each other. What I did was the below and in the logout page:

    navigation.replace('SplashScreen')
    

    My logic was: SplashScreen (Check for AsyncStorage Token),

    if (token){
    navigation.navigate('App')
    }else{
    navigation.navigate('StartScreen')
    }
    

    In StartScreen, just navigate to Signin or Register where you go back to App if login is successful.

    As a reference,

    function AppBottomNavigator(){
      return(
        
            
            
            
            
            
        
      )
    }
    

    export default App stuff...

     ...return(
            
              
                
                  <>
                    
                    
                    
                    
                    
                  
                
              
            
          )
    

    I am also quite new to this but it worked so if someone else has a safer/tidier/general solution, I would quite like to know, too.

提交回复
热议问题