Closed kevinvangelder closed 2 years ago
Alternatively, in dev mode could clicking a link that has no matching route simply log could not find route: ${route}
? It seems I had misconfigured my linking to nest screens, it would have been very useful to know that the route could not be found versus it seeming like the press wasn't even registering.
i believe it should be doing that already…but yeah that sounds useful
I wonder if this would help? https://reactnavigation.org/docs/devtools/
I was only getting errors if the link matched a key that does not exist in the navigation stack or if the link did not exist at all, but my problem was that the link existed but navigation to the key failed because I had nested it (I'm using a BottomTabNavigator and did not fully understand how the linking should be configured). Maybe this is an abnormal enough edge-case that it doesn't need special error handling, but it sure would have saved me a day or two of debugging.
We'd essentially have to manually override the built-in useLinkTo
function from @react-navigation/native
I believe.
It may be a good issue to open on the React Navigation repo. But we could consider overriding the function here to improve the DX.
This code should be throwing an error for you, so it seems like it's able to parse a state from the URL, but it just isn't the desired one?
const state = options?.getStateFromPath
? options.getStateFromPath(to, options.config)
: getStateFromPath(to, options?.config);
if (state) {
const action = getActionFromState(state, options?.config);
if (action !== undefined) {
navigation.dispatch(action);
} else {
navigation.reset(state);
}
} else {
throw new Error('Failed to parse the path to a navigation state.');
}
Maybe we can throw an error if there's no action too (assuming that's what happened).
If you want to reproduce the issue I had you can do so by nesting some valid screens that aren't direct children of the tab navigator in the linking config:
screens: {
Login: '/login',
BottomTabs: {
screens: {
Main: '/home', // Valid child of bottom tabs
UserDetails: '/user/:id', // Deeply nested screen, not a direct descendant
},
}
}
Got it. If you're open to adding a PR / testing it, I'm happy to review it! Thanks for reporting this.
Is there a debug mode I can enable to log Link presses and push/reset/etc calls? My links are working fine in Next but are not working at all in Expo.