Skip to content

Commit

Permalink
[router] fix initial url on web when using baseUrl (#27287)
Browse files Browse the repository at this point in the history
# Why

ENG-11108

When using a baseUrl on web after the initial load a `history.replace`
event is fired which strips the baseUrl. This is caused by React
Navigation examining the current URL (which has the baseURL) and the
`url` attribute on the current focused route (which does not include the
baseURL). As they are different, it assumes the URL is wrong and changes
it via `history.replace`.

# How

I tried to fix this within the existing code, but eventually concluded
that we simply need to fork `useLInking` for web as well. This fork
simply removes the logic to use the URL on the state, and fall back to
`getPathFromState` (which correctly handles baseUrl)


# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
marklawlor and expo-bot committed Mar 12, 2024
1 parent f25f604 commit 5a4eb49
Show file tree
Hide file tree
Showing 15 changed files with 814 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/expo-router/CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@
- Fix `push` navigation not pushing the same route multiple times ([#27307](https://github.com/expo/expo/pull/27307) by [@marklawlor](https://github.com/marklawlor))
- Fix router.navigate will only push when path parameters change ([#27285](https://github.com/expo/expo/pull/27285) by [@marklawlor](https://github.com/marklawlor))
- Fix incorrect route generation of array shared groups with brackets ([#27459](https://github.com/expo/expo/pull/27459) by [@marklawlor](https://github.com/marklawlor))
- Fix incorrect initial URL on web when using baseUrl ([#27287](https://github.com/expo/expo/pull/27287) by [@marklawlor](https://github.com/marklawlor))

### 💡 Others

Expand Down
2 changes: 1 addition & 1 deletion packages/expo-router/build/ExpoRoot.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/expo-router/build/ExpoRoot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/ExpoRoot.js.map

Large diffs are not rendered by default.

56 changes: 54 additions & 2 deletions packages/expo-router/build/fork/useLinking.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-router/build/fork/useLinking.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a4eb49

Please sign in to comment.