Front: Move router to its own component
This commit is contained in:
+13
-10
@@ -1,18 +1,21 @@
|
||||
import { NavigationContainer } from '@react-navigation/native';
|
||||
import { Provider as PaperProvider } from 'react-native-paper';
|
||||
import Theme from './Theme';
|
||||
import { Stack, protectedRoutes, publicRoutes } from './Navigation';
|
||||
import React from 'react';
|
||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||
import { Provider } from 'react-redux';
|
||||
import store from './state/Store';
|
||||
import { Router } from './Navigation';
|
||||
|
||||
const isAuthentified = true;
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<PaperProvider theme={Theme}>
|
||||
<NavigationContainer>
|
||||
<Stack.Navigator>
|
||||
{ isAuthentified ? protectedRoutes : publicRoutes }
|
||||
</Stack.Navigator>
|
||||
</NavigationContainer>
|
||||
</PaperProvider>
|
||||
<Provider store={store}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<PaperProvider theme={Theme}>
|
||||
<Router/>
|
||||
</PaperProvider>
|
||||
</QueryClientProvider>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
|
||||
+16
-2
@@ -1,13 +1,27 @@
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
import React from 'react';
|
||||
import AuthenticationView from './views/AuthenticationView';
|
||||
import HomeView from './views/HomeView';
|
||||
import { NavigationContainer } from '@react-navigation/native';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
export const Stack = createNativeStackNavigator();
|
||||
const Stack = createNativeStackNavigator();
|
||||
|
||||
export const protectedRoutes = <React.Fragment>
|
||||
<Stack.Screen name="Home" component={HomeView} options={{ title: 'Welcome' }} />
|
||||
</React.Fragment>;
|
||||
|
||||
export const publicRoutes = <React.Fragment>
|
||||
<Stack.Screen name="Login" component={AuthenticationView} options={{}} />
|
||||
</React.Fragment>;
|
||||
|
||||
</React.Fragment>;
|
||||
export const Router = () => {
|
||||
const isAuthentified = useSelector((state) => state.user.token !== undefined)
|
||||
return (
|
||||
<NavigationContainer>
|
||||
<Stack.Navigator>
|
||||
{isAuthentified ? protectedRoutes : publicRoutes}
|
||||
</Stack.Navigator>
|
||||
</NavigationContainer>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user