此导航器 3 缺少导航道具

Posted

技术标签:

【中文标题】此导航器 3 缺少导航道具【英文标题】:navigation Prop is missing for this navigator 3 【发布时间】:2019-04-30 02:22:52 【问题描述】:

此导航器缺少导航道具。在 react-navigation 3 中,您必须更直接地设置导航。我查看了有关此的文档,但我仍然无法弄清楚如何将其实现到我的代码中。我做错了什么,我将如何解决它。请提供一些帮助。

这是我的 RootStack.js

import React from 'react';
import  createStackNavigator, createSwitchNavigator  from 'react-navigation';
import SignInScreen from './App/screens/SignInScreen';
import Account from './App/screens/Account';
import Inventory from './App/screens/Inventory';
import Settings from './App/screens/Settings';
import SignUp from './App/screens/SignUp';
import ForgotScreen from './App/screens/ForgotScreen';
import Tournament from './App/screens/Tournament';
import TournamentRsvp from './App/screens/TournamentRsvp';
import Shop from './App/screens/Shop';
import Game from './App/screens/Game';

const routes = 
  SignInScreen: 
    screen: SignInScreen
  ,
  Account: 
    screen: Account
  ,
  Tournament: 
    screen: Tournament
  ,
  TournamentRsvp: 
    screen: TournamentRsvp
  ,
  Shop: 
    screen: Shop
  ,
  Game: 
    screen: Game
  ,
  SignUp: 
    screen: SignUp
  ,
  ForgotScreen: 
    screen: ForgotScreen
  ,
  Settings: 
    screen: Settings
  ,
  Inventory: 
    screen: Inventory
  
;

class AuthLoadingScreen extends React.Component 
  constructor() 
    super();
  


const AppStack = createStackNavigator(routes, 
  headerMode: 'none',
  navigationOptions: 
    headerVisible: false
  ,
  initialRouteName: 'SignInScreen'
);
const AuthStack = createStackNavigator(
  
    SignInScreen: 
      screen: SignInScreen
    
  ,
  
    headerMode: 'none',
    navigationOptions: 
      headerVisible: false
    
  
);

export default createSwitchNavigator(
  
    AuthLoading: AppStack,
    App: AppStack,
    Auth: AuthStack
    // AuthLoading: AppStack,
    // Auth: AuthStack
  ,
  
    initialRouteName: 'AuthLoading'
  
);

这是我的 App.js 下面

import React from 'react';
import  Platform, StatusBar, StyleSheet, View  from 'react-native';
import  AppLoading, Asset, Font, Icon  from 'expo';
import * as firebase from 'firebase';
import  createStackNavigator, createSwitchNavigator  from 'react-navigation';
import  firebaseConfig  from './config.js';
import RootStack from './RootStack';

firebase.initializeApp(firebaseConfig);

export default class App extends React.Component 
  render() 
    return (
      <View style= flex: 1 >
        <RootStack />
      </View>
    );
  

【问题讨论】:

【参考方案1】:

尝试包装在 createAppContainer 中。

import  createAppContainer, createStackNavigator  from 'react-navigation';

export default createAppContainer(createSwitchNavigator(
  
    AuthLoading: AppStack,
    App: AppStack,
    Auth: AuthStack
    // AuthLoading: AppStack,
    // Auth: AuthStack
  ,
  
    initialRouteName: 'AuthLoading'
  
));

【讨论】:

你可以在这里查看吗,***.com/questions/55913460/… 你能解释一下原因吗? @Masterolu 只是参考它会帮助你。 reactnavigation.org/docs/en/hello-react-navigation.html

以上是关于此导航器 3 缺少导航道具的主要内容,如果未能解决你的问题,请参考以下文章

类型中缺少 TypeScript 属性“导航”,但类型“道具”React Native 中需要

如何解决“此导航器同时具有导航和容器道具”错误

React-navigation-redux-helpers 错误:此导航器同时具有导航和容器道具,因此不清楚它是不是应该拥有自己的状态

Xcode 模拟器 - 缺少导航栏

反应原生,侧边菜单没有出现

如何清除或替换传递给根导航器的道具