router icon indicating copy to clipboard operation
router copied to clipboard

Using unstable_settings breaks deep linking in the app when it's in the foreground or background

Open GibbyBox opened this issue 1 year ago • 10 comments

Which package manager are you using? (Yarn is recommended)

yarn

Summary

Exporting unstable_settings (even an empty object) prevents deep linking from working in an app that is in the foreground or the background. The app will be brought to the foreground, just not to the requested screen. Deep linking when the app is closed works fine.

A warning is thrown when this issue occurs.

The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.

I tested this on both router v1.7.7 (repro's master branch) and v2.0.0 (repro's with-router-v2 branch) using the ios simulator. I haven't used android and I tried setting it up to test but uri-scheme wasn't opening up expo :/

Workaround

Currently, I'm using this as a workaround in my app since I need to use unstable_settings for the back button behavior.

	useEffect(function linkingWorkaround() {
		Linking.addEventListener('url', ({ url }) => {
			const match = url.match(new RegExp(`^${SCHEME}:\/\/(.*)`));
			if (match) router.push(match[1]);
		});
	}, []);

Minimal reproducible example

https://github.com/GibbyBox/expo-router-deeplink-repro

GibbyBox avatar Jul 31 '23 13:07 GibbyBox