32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import React from 'react';
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
import { AuthStack } from './authStack';
|
|
import { DrawerStack } from './drawerStack';
|
|
import { useAppSelector } from '../store/store';
|
|
import { RootState } from '../store/rootReducer';
|
|
|
|
export type RootStackParamList = {
|
|
AuthStack: undefined;
|
|
DrawerStack: undefined;
|
|
};
|
|
|
|
const RootStack = createNativeStackNavigator<RootStackParamList>();
|
|
|
|
export const RootNavigator = () => {
|
|
const { token } = useAppSelector((state: RootState) => state.auth);
|
|
const initialRouteName = token ? 'DrawerStack' : 'AuthStack';
|
|
|
|
return (
|
|
<NavigationContainer>
|
|
<RootStack.Navigator
|
|
screenOptions={{ headerShown: false }}
|
|
initialRouteName={initialRouteName}
|
|
>
|
|
<RootStack.Screen name="AuthStack" component={AuthStack} />
|
|
<RootStack.Screen name="DrawerStack" component={DrawerStack} />
|
|
</RootStack.Navigator>
|
|
</NavigationContainer>
|
|
);
|
|
};
|