I’m really sorry for the title being so long on this question but I’m pretty stumped on it.
Ive been working a react native login page for around 10 days now and after finishing all the server side logic it is time to provide login by token functionality.
So my current issue is that I can use navigation.navigate() in all the components that are part of the and the <Stack.Navigator>.
For my login page I designed a function to authenticate them based on stored tokens. This function works but after calling it and getting the desired response I wish to move them to the home screen of the app.
const Stack = createNativeStackNavigator();
export default function App({navigation}) {
async function validate(){
let key =await getKey('token')
let retval = await Http.post('/verify',{token:key})
return retval.status
}
validate().then(function(value){
if(value==215){
}
}).catch(function(error){
console.log(error)
})
navigation.navigate('Home')
return (
<NavigationContainer>
<Stack.Navigator >
<Stack.Screen
options={{headerShown: false}}
name='Login'
component={Login}
/>
<Stack.Screen
name='Sign-up'
component={Signup}
/>
<Stack.Screen
options={{headerShown: false}}
name='Home'
component={Home}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
So this code results in a undefined property error but I’m mainly asking for a solution to navigate from the encapsulating component.
2
Answers
The best way to do this is using a navigationRef.
https://reactnavigation.org/docs/navigating-without-navigation-prop/
you can use Passing parameters to routes navigation
and get
https://reactnavigation.org/docs/params/