Im trying to handle the error
The action 'NAVIGATE' with payload .. was not handled by any navigator
- tried having a no route match. the documentation says:
const config = {
screens: {
Home: {
initialRouteName: 'Feed',
screens: {
Profile: 'users/:id',
},
},
NotFound: '*',
},
};
Im not sure if I need to add anything else, but like that its not working.
- I tried using error boundary and wrap my navigator in this. my error boundary works fine but it doesnt catch navigation errs. Not sure if its not suppose to catch them or something is wrong with my code.
App.js
const App = () => {
const config = {...}
return (
<NotificationsProvider>
<Navigator linking={linking}/>
</NotificationsProvider>
);
}
Navigator.js
<NavigationContainer ref={navigationRef} linking={linking}>
<MyStack />
</NavigationContainer>
MyStack:
const MyStack = () => {
return (
<ErrorBoundary
FallbackComponent={FallbackWithoutReset}
onError={onError}
navigation={navigation}
>
<Stack.Navigator navigation={navigation}>
<Stack.Group>
...
</Stack.Group>
<Stack.Group>
</Stack.Screen>
<Stack.Screen
name="Settings"
component={SettingsScreen}
/>
</Stack.Group>
...
<Stack.Screen name="NotFound" component={NotFoundScreen} />
</Stack.Navigator>
</ErrorBoundary>
)
}
You could use the onUnhandleAction function of the
NavigationContainercomponent. As written in the documentationThus, you can catch any "was not handled by any navigator"-error via the
onUnhandleActionfunction.Then, if you want to navigate to a fallback route, you could use the
useNavigationContainerRefhook.Here is a minimal working example and the corresponding snack.