nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 180 forks source link

Rewriting the url using the `as` parameter clears params on native. #467

Closed crewtaylorfd closed 8 months ago

crewtaylorfd commented 9 months ago

Is there an existing issue for this?

Do you want this issue prioritized?

Current Behavior

If I do the following

const router = useRouter()
router.push({
      pathname: `/video/${id}`,
      query: params,
}, `/video/${id}`)

The params are not accessible on native. If I remove the as parameter, the second argument to router.push(), in this case it is /video/${id}, the params come back.

Expected Behavior

If I pass in an as parameter to the push function the params should still be accessible on native

Steps To Reproduce

  1. Create a solito project
  2. Use the push function with the as parameter to rewrite the URL.
  3. Check the params on native and see if you get you query params you passed into the push function

Versions

- Solito:
- Next.js:
- Expo:
- React Native:

Screenshots

No response

Reproduction

No response

nandorojo commented 9 months ago

The asPath will be used on native. Is there a reason to not pass the asPath and have that be what it links to?

crewtaylorfd commented 9 months ago

The asPath will be used on native. Is there a reason to not pass the asPath and have that be what it links to?

I would like to rewrite the url to hide the query params when on web. That is why I am passing the as argument here to write the url to just the pathname.

nandorojo commented 9 months ago

You could pass asPath on web only

crewtaylorfd commented 9 months ago

Got it. Wanted to see if there was a way to do it without writing any Platform.OS === 'web' code.

nandorojo commented 9 months ago

The as path in my mind is where the native app should go. Because if you want to jump from the website into the app, the browser is going to use what’s in the actual address bar. Hiding params is a rare case on web, typically reserved for modals on top of list pages. And in that case the as path is enough on native

It might be worth asking if hiding the query params is what you actually should be doing here (though I don’t know the use case)

Hiding params can also mess up refreshing, but this shouldn’t matter on native if the as path has the correct params in it too