-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigator.tsx
55 lines (48 loc) · 1.34 KB
/
Navigator.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, {useEffect} from 'react';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {ScreenOne} from './src/ScreenOne';
import {ScreenTwo} from './src/ScreenTwo';
import {NavigationProp, useNavigation} from '@react-navigation/native';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
enum Screen {
Screen1 = 'screen-one',
Screen2 = 'screen-two',
}
type RootStackParamList = {
[Screen.Screen1]: undefined;
[Screen.Screen2]: undefined;
};
const Stack = createNativeStackNavigator<RootStackParamList>();
type Props = {
page: string;
};
export type StackNavigation = NavigationProp<RootStackParamList>;
export const Navigator = (props: Props) => {
const navigation = useNavigation<StackNavigation>();
useEffect(() => {
console.log('props: ', props);
if (props.page === 'router2') {
navigation.navigate(Screen.Screen2);
} else {
navigation.navigate(Screen.Screen1);
}
}, [navigation, props]);
return (
<Stack.Navigator>
<Stack.Screen
name={Screen.Screen1}
component={ScreenOne}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name={Screen.Screen2}
component={ScreenTwo}
options={{
headerShown: false,
}}
/>
</Stack.Navigator>
);
};