I am using ReactNative application, route.ts
import React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import Login from './src/screens/Login';
import Dashboard from './src/screens/Dashboard';
import {navigationRef} from './src/RootNavigation';
export const RootStack = createStackNavigator();
const Home = () => {
return (
<NavigationContainer ref={navigationRef}>
<RootStack.Navigator initialRouteName={'Login'}>
<RootStack.Screen name="Login" component={Login} />
<RootStack.Screen name="Dashboard" component={Dashboard} />
</RootStack.Navigator>
</NavigationContainer>
);
}
export default Home;
RootNavigation.ts
import React from 'react';
export const navigationRef: any = React.createRef();
export function navigate(name: any, params: any) {
navigationRef.current.navigate(name, params);
}
Login.tsx
import * as Navigation from '../RootNavigation';
loginAttempt = () => {
if (
this.state.username === this.props.userData.username &&
this.state.password === this.props.userData.password
) {
Navigation.navigate('Dashboard ', {});
} else {
Alert.alert('Please try again with correct username and password');
}
};
Here I am facing issues error while navigating from one screen to another screen; The action 'NAVIGATE' with payload {"name":"Dashboard ","params":{}} was not handled by any navigator.
Do you have a screen named 'Dashboard '?
If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.