用户通过身份验证后,如何导航用户登录屏幕?

时间:2019-03-28 12:13:38

标签: react-native react-redux react-navigation react-navigation-stack

我有一个root StackNavigator,其中有另外两个导航器 1个堆栈导航器(登录,注册) 2个标签导航器(主页,个人资料,设置)

那么当用户登录成功时,如何从rootNavigator导航到tabNavigator?

import React from 'react';
import { createStackNavigator, createAppContainer } from 'react-navigation'

import authNavi from './AuthRoute';  /// this is StackNavigator with login signup screen

import appNavi from './AppRoute' /// this is tabNAvigator with profile home setting screen

const RootRoute = createStackNavigator({ 

    auth: {screen: authNavi },
    app: {screen: appNavi }
})

const RootNavi = createAppContainer(RootRoute);
export default RootNavi;  /// this is rootNavigator whih is rendered in App.js

here is the image of App.js and RootRouter

2 个答案:

答案 0 :(得分:1)

您可以通过以下方式从身份验证堆栈导航到tabNavigator:

this.props.navigation.navigate('app');

建议 我建议您用SwitchNavigator替换主StackNavigator ... ...因为在用户成功登录后,您将不需要他们再次访问您的身份验证流。

答案 1 :(得分:1)

通过使用Switch Navigator,您可以实现这一目标。

createSwitchNavigator导入react-navigation

例如:

import {
  createAppContainer,
  createStackNavigator,
  ...
  createSwitchNavigator
} from "react-navigation";

之后,添加开关导航器。

...
const switchNavigator = createSwitchNavigator(
  {
    LoginStack: authNavi,
    AppTabs: appNavi
  },
  { headerMode: "none", initialRouteName: "LoginStack" }
);

const App = createAppContainer(switchNavigator);

export default App;

当您想换家时,请使用此

this.props.navigation.navigate("AppTabs");

它将导航切换到TabBar导航。