【问题标题】:Navigate from one stack to another从一个堆栈导航到另一个堆栈
【发布时间】:2019-05-19 13:33:28
【问题描述】:

我有一个嵌套的导航结构。
登录屏幕需要导航到个人资料屏幕,而个人资料需要导航到收件箱。像这样,登录 -> 个人资料 -> 收件箱。

唱歌

import React, {Component} from 'react';
import Profile from "../Profile";

class AppSignIn extends React.Component{

_doSignIn(){
 this.props.navigation.navigate('Profile')
}

render(){
  return(
     <View>
      <TouchableHighlight onPress={this._doSignIn.bind(this)}>
          <Text>Go to Profile</Text>
      </TouchableHighlight>
     </View>
    )
 }
}

const AppSignInNav = createStackNavigator(
 {
    AppSignIn:{
    screen : AppSignIn
  },
  Profile:{
    screen:Profile
  }
 });

 export default createAppContainer(AppSignInNav);


个人资料

import React, {Component} from 'react';
import Inbox from "../Inbox";

class Profile extends React.Component{

_goToInbox(){
 this.props.navigation.navigate('Inbox')
}

render(){
  return(
     <View>
      <TouchableHighlight onPress={this._goToInbox.bind(this)}>
          <Text>Go to Inbox</Text>
      </TouchableHighlight>
     </View>
    )
 }
}

const ProfileNav = createStackNavigator(
 {
    Profile:{
    screen : Profile
  },
  Inbox:{
    screen : Inbox
  }
 });

 export default createAppContainer(ProfileNav);

我是如何因为尝试从 createStackNavigator 导航到另一个而收到此错误的。 The component for route 'Profile' must be a React component...
如何将 Profile 导出为 React 组件,但仍要导航到 Inbox。?

【问题讨论】:

  • 试试export default ProfileNav而不是export default createAppContainer(ProfileNav)

标签: react-native stack-navigator


【解决方案1】:

导航只能有一个appContainer。您正在尝试使用 createAppContainer 两次创建应用容器。

您可以使用AppSignInNav 作为应用容器,并将ProfileNav 导出为普通的StackNavigator

有关createAppContainer 及其用途的详细信息,请参阅this 链接。

【讨论】:

  • 谢谢 Nair,我已经意识到我的问题是什么......这个问题更像是一个鸡蛋问题。我在 Profile 中导入 SignIn 并在 SignIn 中导入 Profile 这是一个不好的方法。
猜你喜欢
  • 2019-10-08
  • 2013-07-23
  • 2020-07-27
  • 1970-01-01
  • 2020-04-03
  • 2013-04-29
  • 1970-01-01
  • 2013-12-26
  • 1970-01-01
相关资源
最近更新 更多