router icon indicating copy to clipboard operation
router copied to clipboard

useSegment and usePathname return the wrong value on deeplinking

Open wcastand opened this issue 1 year ago • 1 comments

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

yarn

Summary

Bug deeplink

Using the expo-router template: npx create-expo-app@latest --example with-router update react-native for warning npx expo install --check

  • On a macbook air: M1 apple chip
  • testing on iOS simulator

When coming from a deeplink, the hook like useSegments or usePathname don't have the right value. i tried with and without unstable_settings and the result are the same.

If you do something like npx uri-scheme open "exp://192.168.1.9:19000/--/home" --ios It will render the right screen (home) but the hook will return

 LOG  /undefined ["[...404]"]

I don't know if expo go is using deeplink by default to open the app because it also happens on reload in this example.

The app i'm working on only has the wrong pathname on deeplink (using expo-dev)

In my app the first render from the deeplink has the right screen( the one requested in deeplink) but the hook return / for pathname and [] for segments.

Bug received / expected

  • deeplink to the app
npx uri-scheme open "exp://192.168.1.9:19000/--/home" --ios

received:

 LOG  /undefined ["[...404]"]

expected:

 LOG  /home ["home"]

Minimal reproducible example

https://github.com/wcastand/deeplinkbug

wcastand avatar May 10 '23 15:05 wcastand