Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePathname() doesn't work with expo-router #445

Open
2 of 3 tasks
hamsterhomka opened this issue Nov 4, 2023 · 4 comments
Open
2 of 3 tasks

usePathname() doesn't work with expo-router #445

hamsterhomka opened this issue Nov 4, 2023 · 4 comments

Comments

@hamsterhomka
Copy link

hamsterhomka commented Nov 4, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Do you want this issue prioritized?

  • Yes, I have sponsored
  • Not urgent

Current Behavior

usePathname() returns undefined in expo application with expo-router.

Expected Behavior

Work the same as in next.js

Steps To Reproduce

No response

Versions

- Solito: 4.0.1
- Next.js: 13.5.4
- Expo: 49
- React Native: 0.72.4

Screenshots

I think that usePathname from 'solito/navigation' should use usePathname from 'expo-router' under the hood instead of useContext(NavigationRouteContext)

Reproduction

No response

@hamsterhomka
Copy link
Author

hamsterhomka commented Nov 4, 2023

Created two files

  1. usePathname.ts
import { usePathname as useExpoPathname } from 'expo-router'

export const usePathname = () => {
  return useExpoPathname()
}
  1. usePathname.web.ts
import { usePathname as useNextPathname } from 'next/navigation'

export const usePathname = () => {
  return useNextPathname()
}

And it worked perfectly!

@nandorojo
Copy link
Owner

Hm interesting. Well what you did is correct!

@gijosso
Copy link

gijosso commented Dec 8, 2023

  1. usePathname.web.ts
import { usePathname as useNextPathname } from 'next/navigation'

export const usePathname = () => {
  return useNextPathname()
}

@hamsterhomka usePathname from solito/navigation works and does exactly that, so you could just do:

 import { usePathname } from 'solito/navigation'

 export { usePathname } 

Trying to figure out a way to get the expected behaviour on native without the expo/router dependency but no luck so far.

The comment can be edited though, it doesn't work with the expo router.

@nandorojo Is there a relevant way to add a warning about this unexpected behaviour ?

@nandorojo
Copy link
Owner

Yeah we probably need a config variable for expo router at the root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants