我有一个身份验证屏幕,我正在那里进行身份验证工作,但是在成功登录后,我想将堆栈重置为主屏幕。但我收到此错误,因为屏幕未定义。
应用程序.js
import React, {Component} from 'react'
import {SafeAreaView, Button, Text} from 'react-native'
import firebase from 'firebase'
import {firebaseConfig} from './fireabase.config'
// Navigation from react-navigation
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
// SCREENS
import AuthTabNavigator from './src/screens/authScreen/TabNavigator';
import DrawerNavigator from './src/screens/appScreen/DrawerNavigator';
// Redux Imports
import {Provider} from 'react-redux';
import store from './src/store';
import {AUTH, DRAWER, HOME} from './src/constants/navigation.constants';
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig)
}
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
import Login from './src/screens/authScreen/Login';
import Signup from './src/screens/authScreen/Signup';
const AuthNavigator = () => {
return (
<Tab.Navigator>
<Tab.Screen name={'LOGIN'} component={Login} />
<Tab.Screen name={'SIGNUP'} component={Signup} />
</Tab.Navigator>
)
}
class App extends Component {
render () {
return (
<SafeAreaView style={{flex: 1}}>
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name={AUTH}
component={AuthNavigator}
options={{
headerShown:false
}}
/>
<Stack.Screen
name={DRAWER}
component={DrawerNavigator}
options={{
headerShown:false
}}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
</SafeAreaView>
)
}
}
export default App
DrawerNavigator.js
import React, {Component} from 'react'
import { createStackNavigator } from '@react-navigation/stack';
import {createDrawerNavigator} from '@react-navigation/drawer';
import { Text, TouchableOpacity } from 'react-native';
const Drawer = createDrawerNavigator();
// Components
import Home from './Home';
import Profile from './Profile';
import Sounds from './Sounds';
// NAVIGATION CONSTANTS
import {HOME, PROFILE, SOUNDS} from '../../constants/navigation.constants';
const Stack = createStackNavigator();
const HomeScreen = ({ navigation }) => {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={Home}
options={{
title: 'HOME',
headerShown: true,
headerLeft: () => <HanmurgerMenu navigation={navigation}/>
}}
/>
</Stack.Navigator>
);
};
const ProfileScreen = ({navigation}) => {
return (
<Stack.Navigator>
<Stack.Screen name="Profile" component={Profile}
options={{
title: 'Profile',
headerShown: true,
headerLeft: () => <HanmurgerMenu navigation={navigation}/>
}}
/>
</Stack.Navigator>
);
};
const SoundScreen = ({navigation}) => {
return (
<Stack.Navigator>
<Stack.Screen name="Profile" component={Sounds}
options={{
title: 'Sounds',
headerShown: true,
headerLeft: () => <HanmurgerMenu navigation={navigation}/>
}}
/>
</Stack.Navigator>
);
};
function HanmurgerMenu({navigation}){
return (
<TouchableOpacity
style={{ padding: 5 }}
onPress={()=> navigation.openDrawer()}>
<Text style={{ fontSize: 20 }}> ☰ </Text>
</TouchableOpacity>
)
}
function DrawerNavigator() {
return (
<Drawer.Navigator initialRouteName={HOME}>
<Drawer.Screen name={'HOME'} component={HomeScreen} />
<Drawer.Screen name={'PROFILE'} component={ProfileScreen} />
<Drawer.Screen name={'SOUNDS'} component={SoundScreen} />
</Drawer.Navigator>
);
}
export default DrawerNavigator;
成功登录后在 Login.js 内我正在这样做
navigation.navigate('DRAWER');
如何将堆栈从 LOGIN 删除到 DRAWER