I tried all the examples in the doc but no success.
I have component that I am routing from here to component.
I need to unmount component A.
I've tried REPLACE AND RESET.
RootNavigation.navigationRef.current.dispatch(state => {
return CommonActions.reset({
index: 0,
key: null,
routes: [{ name: 'B' }],
});
});
this code function route me to different route routs in stack['AA','B'] so it routes me to 'AA'
const resetAction = StackActions.replace('B', {});
RootNavigation.navigationRef.current.dispatch(state => {
return resetAction;
});
I AM GETTING AN ERROR he action 'REPLACE' with payload {"name":"B","params":{}} was not handled by any navigator.
RootNavigation.navigate('B');
this function work great but it's not unmounted A.
you can use like this, create file name 'RootNavigation' and then enter these lines
import {createNavigationContainerRef} from '@react-navigation/native';
import {StackActions} from '@react-navigation/native';
export const navigationRef = createNavigationContainerRef();
export function navigate(name, params) {
if (navigationRef.isReady()) {
navigationRef.navigate(name, params);
}
}
export function navigateReplace(name, param) {
if (navigationRef.isReady()) {
navigationRef.dispatch(
StackActions.replace(name, {
param,
}),
);
}
}
if you wont to navigate without navigation props. import 'RootNavigation', like this
import * as RootNavigation from '../RootNavigation';
then you can navigate like this
RootNavigation.navigateReplace('Login Flow');
or
RootNavigation.navigate('Profile');
please refer `https://reactnavigation.org/docs/navigating-without-navigation-prop/` this official document
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With