问题很简单,我知道同一个问题有很多答案,但我有不同的设置我自己的App.js个文件,我try 了几乎所有,但没有成功.

所以我的App.js看起来像这样

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  StatusBar
} from 'react-native';
import { createStackNavigator  } from 'react-navigation';
import { Header, Button, Spinner } from './src/components/comman';
import SplashScreen from 'react-native-splash-screen';
import LoginForm from './src/components/LoginForm';
import SignupForm from './src/components/SignupForm';
import Home from './src/components/Home';
import ForgetPassword from './src/components/ForgetPassword';


import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);
const App = createStackNavigator ({
  Login: { screen: LoginForm },
  Home: { screen: Home },
  Signup: { screen: SignupForm },
  ForgetPassword: { screen : ForgetPassword },
  },
  { 
  initialRouteName: 'Login',
  });

export default App;

现在我将登录状态存储在我的LoginForm.js中的AsyncStorage中,如下所示

.
.
AsyncStorage.setItem('isLoggedIn', 'true').then((a) => {
    this.onLoginSuccess(responseData.user_id);
});
.
.

现在我想根据本地存储元素设置initialRouteName.

简单但不知道如何在my App.js中使用它

请帮忙:)

推荐答案

正如你看到的here:

如果需要将initialRouteName设置为props ,那是因为在呈现应用程序导航之前,需要异步获取一些数据.另一种处理方法是使用switchnavigator,并在获取异步数据时显示屏幕,然后在必要时使用参数导航到适当的初始路由.请参阅docs了解完整的示例.

这是一个开放的RFC

使现代化

看看here.

你会找到更多的描述!

React-native相关问答推荐

Redux将旧状态迁移到新状态

1.5.1 nxworkspace+react-native 版本的Axios url未定义问题

错误发生意外错误:https://registry.yarnpkg.com/react-native-template-react-native-template-typescript:未找到

如何解决Readonly<{}> 类型上不存在属性 navigation&

Invariant Violation:Chrome 不支持在本机模块上调用同步方法

用于部署后设置的 React 配置文件

React Native this.'function' 不是函数

如何在 react-native 中在子级和父级之间传递数据?

api.get(...).then(...).catch(...).finally 不是函数

React 中的 getSnapshotBeforeUpdate() 是什么?

No such property: ABI for class: org.gradle.api.tasks.OutputFile

在本react-native中具有异步和等待的箭头函数

react-native图标

任务在 react-native 中因请求而成为orphaned - 这是什么意思?

将 react-native 元素Bundle 为 iOS 框架或 (.aar) Android 库

React Native - Firebase 身份验证持久性不起作用

ListView 和 FlatList 有什么区别?

Expo在使用Windows 10的android模拟器上运行

react-native构建错误:package android.support.annotation does not exist

React Native:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败