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
[router] fix initial url on web when using baseUrl #27287
Conversation
Readded focused route logic. Just append the baseURL to this line of code https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/native/src/useLinking.tsx#L280 |
@@ -1,3 +1,405 @@ | |||
import useLinking from '@react-navigation/native/lib/module/useLinking'; | |||
/* eslint-disable */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All Forked sections have Start of fork/End of fork
code comments
// ServerContext is used inside ServerContainer to set the location during SSR: https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/native/src/ServerContainer.tsx#L50-L54 | ||
// Expo Router uses the `initialLocation` prop to set the initial location during SSR: | ||
const location = React.useContext(ServerLocationContext); | ||
const server = { location }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EvanBacon I'm not sure this behaviour is correct.
ServerContext
is only used in React Navigation inside the ServerContainer
to set the initial URL https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/native/src/ServerContainer.tsx#L50-L54
But Expo Router never sets the location during renderToStaticContent
<ServerContainer ref={ref}>{element}</ServerContainer> |
If I were to replicate this current behaviour exactly, I should just remove ServerContext
. Instead I've replaced it with a new context (the Provider sets the location in ExpoRoot)
036073a
to
b69f958
Compare
Note: Test without JavaScript enabled |
b69f958
to
9645031
Compare
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
9645031
to
1b6d169
Compare
…xt (#27712) # Why This should have been part of #27287 Forks the `NavigationContainer` to use the custom `useLinking` which appends the baseURL to the redirect that React Navigation performs when current state != focused state # Test Plan Tested using @byCedric's repo https://github.com/byCedric/expo-issue-router-base-url --------- Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
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 theurl
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 viahistory.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 togetPathFromState
(which correctly handles baseUrl)Test Plan
Checklist
npx expo prebuild
& EAS Build (eg: updated a module plugin).