反应本机导航错误导航问题

时间:2020-02-05 07:10:16

标签: reactjs react-native react-native-navigation

我正在尝试创建本机应用程序,但是它抛出错误。我使用了react-native-navigation。 (我正在尝试创建React Native应用程序。但是它引发了错误。我使用了react-native-navigation。)

import { createAppContainer, createSwitchNavigator } from "react-navigation";
import { createStackNavigator } from "react-navigation-stack";
import { createBottomTabNavigator } from "react-navigation-tabs";
import DashboardScreen from "./src/component/Dashboard";
import LoginScreen from "./src/component/Auth/Login";
import RegisterScreen from "./src/component/Auth/Register";

const AppStack = createStackNavigator({ Dashboard: DashboardScreen });
const AuthStack = createBottomTabNavigator({
  SignIn: LoginScreen,
  Register: RegisterScreen
});

export const RootNaviation = () => {
  return createAppContainer(
    createSwitchNavigator(
      {
        Auth: AuthStack,
        App: AppStack
      },
      { initialRouteName: "Auth" }
    )
  );
}; 

应用文件

import React from "react";
import { StyleSheet, Text, View, Button } from "react-native";
import { SwitchNavigator } from "./Router";
const Nav = SwitchNavigator();

export default function App() {
  return (
    <View style={styles.container}>
      <Button title="dafdlka" />
      <Nav />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center"
  }
});

enter image description here

1 个答案:

答案 0 :(得分:0)

您从未创建过名为SwitchNavigator的变量。

您可以使用RootNaviation

import { RootNaviation } from "./Router"
...
export default function App() {
  return (
    <View style={styles.container}>
      <Button title="dafdlka" />
      <RootNaviation />
    </View>
  );
}