How to set dynamic initialRouteName in createSwitchNavigator?(如何在 createSwitchNavigator 中设置动态 initialRouteName?)
问题描述
我想设置身份验证流程,但我没有从 SecureStore 获取数据
I want to setup auth flow but i'm not getting the data from SecureStore
Navigator.js
Login.js
来自 console.log(SecureStore.getItemAsync('isSignedIn')) 的响应;
现在,由于 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.
喜欢这样做:
并在 AUthLoading
希望清楚
这篇关于如何在 createSwitchNavigator 中设置动态 initialRouteName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!