<bdo id='g1oRY'></bdo><ul id='g1oRY'></ul>
    1. <tfoot id='g1oRY'></tfoot>
    2. <legend id='g1oRY'><style id='g1oRY'><dir id='g1oRY'><q id='g1oRY'></q></dir></style></legend>
      1. <i id='g1oRY'><tr id='g1oRY'><dt id='g1oRY'><q id='g1oRY'><span id='g1oRY'><b id='g1oRY'><form id='g1oRY'><ins id='g1oRY'></ins><ul id='g1oRY'></ul><sub id='g1oRY'></sub></form><legend id='g1oRY'></legend><bdo id='g1oRY'><pre id='g1oRY'><center id='g1oRY'></center></pre></bdo></b><th id='g1oRY'></th></span></q></dt></tr></i><div id='g1oRY'><tfoot id='g1oRY'></tfoot><dl id='g1oRY'><fieldset id='g1oRY'></fieldset></dl></div>

        <small id='g1oRY'></small><noframes id='g1oRY'>

      2. 如何在 createSwitchNavigator 中设置动态 initialRouteName?

        时间:2023-11-29

            <tbody id='imcqP'></tbody>

          <small id='imcqP'></small><noframes id='imcqP'>

          1. <i id='imcqP'><tr id='imcqP'><dt id='imcqP'><q id='imcqP'><span id='imcqP'><b id='imcqP'><form id='imcqP'><ins id='imcqP'></ins><ul id='imcqP'></ul><sub id='imcqP'></sub></form><legend id='imcqP'></legend><bdo id='imcqP'><pre id='imcqP'><center id='imcqP'></center></pre></bdo></b><th id='imcqP'></th></span></q></dt></tr></i><div id='imcqP'><tfoot id='imcqP'></tfoot><dl id='imcqP'><fieldset id='imcqP'></fieldset></dl></div>
            • <tfoot id='imcqP'></tfoot>
                <legend id='imcqP'><style id='imcqP'><dir id='imcqP'><q id='imcqP'></q></dir></style></legend>
                  <bdo id='imcqP'></bdo><ul id='imcqP'></ul>
                • 本文介绍了如何在 createSwitchNavigator 中设置动态 initialRouteName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想设置身份验证流程,但我没有从 SecureStore 获取数据

                  I want to setup auth flow but i'm not getting the data from SecureStore

                  Navigator.js

                  const AppSwitchNavigator = createSwitchNavigator(
                    {
                      SignedOut,
                      SignedIn
                    },
                    {
                      initialRouteName: AsyncStorage.getItem('isSignedIn') == 'true' ? 'SignedIn' : 'SignedOut'
                    }
                  )
                  export default createAppContainer(AppSwitchNavigator)
                  

                  Login.js

                    verifyOtp = async code => {
                      const { phone } = this.state
                  
                      var response = await Axios.post(
                        `https://api.msg91.com/api/v5/otp/verify?mobile=91${phone}&otp=${code}&authkey=273478A4j3qbKgj5cbda6ba`
                      )
                  
                      if (response.data.type == 'error') {
                        this.setState({
                          errMsg: response.data.message
                        })
                      } else {
                        await SecureStore.setItemAsync('isSignedIn', 'true')
                        this.props.navigation.navigate('Home')
                      }
                    }
                  

                  来自 console.log(SecureStore.getItemAsync('isSignedIn')) 的响应;

                  undefined
                  true
                  true
                  undefined
                  true
                  true
                  undefined
                  true
                  true
                  

                  现在,由于 initialRouteName 没有获得 isSignedIn 的值,因此它始终保留在 SignedOut 页面上,即登录页面.

                  Now since initialRouteName is not getting the value of isSignedIn it always remains on SignedOut Page i.e. Login Page.

                  推荐答案

                  这是一个几乎每个人都会遇到的经典案例,所以根据 react navigation 的文档 rn-docs,他们总是说最好有 3 个页面,并将初始页面加载为启动屏幕,并在 componentDidMount 方法中启动屏幕执行 asyncstorage 的操作并进行相应的导航.

                  This is a classic case which almost everyone faces, so as per the docs of react navigation rn-docs, they always say the best thing is to have 3 pages , and load the initial page as splash screen, and inside the componentDidMount method of splash screen do the asyncstorage thing and navigate accordingly.

                  喜欢这样做:

                   export default createAppContainer(
                        createSwitchNavigator(
                          {
                            AuthLoading: AuthLoadingScreen,
                            App: AppStack,
                            Auth: AuthStack,
                          },
                          {
                            initialRouteName: 'AuthLoading',
                          }
                        )
                      );
                  

                  并在 AUthLoading

                  class AuthLoadingScreen extends React.Component {
                    componentDidMount() {
                      this._bootstrapAsync();
                    }
                  
                    // Fetch the token from storage then navigate to our appropriate place
                    _bootstrapAsync = async () => {
                      const userToken = await AsyncStorage.getItem('userToken');
                  
                      // This will switch to the App screen or Auth screen and this loading
                      // screen will be unmounted and thrown away.
                      this.props.navigation.navigate(userToken ? 'App' : 'Auth');
                    };
                  
                    // Render any loading content that you like here
                    render() {
                      return (
                        <View>
                          <ActivityIndicator />
                          <StatusBar barStyle="default" />
                        </View>
                      );
                    }
                  }
                  

                  希望清楚

                  这篇关于如何在 createSwitchNavigator 中设置动态 initialRouteName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:expo-video-player 出现问题,它抛出错误:setAudioModeAsync 下一篇:React Native 选项卡视图的高度始终等于最高选项卡的高度

                  相关文章

                  <legend id='TwiK4'><style id='TwiK4'><dir id='TwiK4'><q id='TwiK4'></q></dir></style></legend>
                  <tfoot id='TwiK4'></tfoot>
                    • <bdo id='TwiK4'></bdo><ul id='TwiK4'></ul>

                      <i id='TwiK4'><tr id='TwiK4'><dt id='TwiK4'><q id='TwiK4'><span id='TwiK4'><b id='TwiK4'><form id='TwiK4'><ins id='TwiK4'></ins><ul id='TwiK4'></ul><sub id='TwiK4'></sub></form><legend id='TwiK4'></legend><bdo id='TwiK4'><pre id='TwiK4'><center id='TwiK4'></center></pre></bdo></b><th id='TwiK4'></th></span></q></dt></tr></i><div id='TwiK4'><tfoot id='TwiK4'></tfoot><dl id='TwiK4'><fieldset id='TwiK4'></fieldset></dl></div>
                    1. <small id='TwiK4'></small><noframes id='TwiK4'>