我想根据异步存储中的密钥动态呈现初始路由。有很多方法可以做到这一点,但就我而言,我找不到任何工作。这是我的导航器文件。
import {
createDrawerNavigator,
DrawerNavigatorItems,
} from 'react-navigation-drawer';
const WINDOW_WIDTH = Dimensions.get('window').width;
const getRoute = ()=>{
return "SignUpScreen";
}
const DrawerNavigator = createDrawerNavigator(
{
Home: {
path: '/home',
screen: Home,
},
SignUpScreen:{
path: '/signup',
screen: SignUpScreen
},
OtpScreen: {
path: '/otpscreen',
screen: OtpScreen
}
},
{
initialRouteName: `${getRoute()}`,
contentOptions: {
activeTintColor: `${THEME_VARIABLES.COLORS.PRIMARY_TEXT}`,
activeBackgroundColor: 'transparent',
inactiveTintColor: `${THEME_VARIABLES.COLORS.PRIMARY_TEXT}`,
inactiveBackgroundColor: 'transparent',
backgroundColor: `${THEME_VARIABLES.COLORS.PRIMARY_THEME}`,
labelStyle: {
fontSize: 15,
marginLeft: 0,
},
},
drawerWidth: Math.min(WINDOW_WIDTH * 0.6, 300),
contentComponent: customContentComponent,
}
);
export default DrawerNavigator;
要在 getRote() 中使用 asyncStorage,我必须执行类似的操作
const getRoute = async()=>{
var initialRouteName = await AsyncStorage.getItem('screen');
return initialRouteName;
}
但是当我使用异步时,函数返回一个对象而不是字符串,就像它在我的第一个 getRoute 函数(没有异步的函数)中返回的那样。它显示以下错误: