You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with url at https://host/#/foo/bar, calling history.replace({path: '#/foo/baz', ...}) sets the new url to https://host/#/foo/baz/#/foo/bar.
This conflicts with using react-navigation with a 'hash router' method.
Source of the issue is this code, which intentionally adds location.hash to the path.
replace({ path, state }: { path: string; state: NavigationState }) {
interrupt();
const id = window.history.state?.id ?? nanoid();
// Need to keep the hash part of the path if there was no previous history entry
// or the previous history entry had the same path
let pathWithHash = path;
if (!items.length || items.findIndex((item) => item.id === id) < 0) {
// There are two scenarios for creating an array with only one history record:
// - When loaded id not found in the items array, this function by default will replace
// the first item. We need to keep only the new updated object, otherwise it will break
// the page when navigating forward in history.
// - This is the first time any state modifications are done
// So we need to push the entry as there's nothing to replace
pathWithHash = pathWithHash + location.hash;
items = [{ path: pathWithHash, state, id }];
index = 0;
} else {
if (items[index].path === path) {
pathWithHash = pathWithHash + location.hash;
}
items[index] = { path, state, id };
}
window.history.replaceState({ id }, '', pathWithHash);
},
Expected behavior
The location url could/should drop location.hash if the new path has a hash in it, because there's no world where we'd want to have two hash parts.
resulting location for above case would be: https://host/#/foo/baz
I'll add that there is a workaround, but it's a bit of a hack. when I extract the hash part of the url on first page load, I blow away the current hash so this code can't reappend it. Not ideal.
Current behavior
with url at
https://host/#/foo/bar
, callinghistory.replace({path: '#/foo/baz', ...})
sets the new url tohttps://host/#/foo/baz/#/foo/bar
.This conflicts with using react-navigation with a 'hash router' method.
Source of the issue is this code, which intentionally adds
location.hash
to the path.Expected behavior
The location url could/should drop
location.hash
if the new path has a hash in it, because there's no world where we'd want to have two hash parts.resulting location for above case would be:
https://host/#/foo/baz
Reproduction
https://snack.expo.dev/@jmbldwn/react-navigation-has-repro
Platform
Packages
Environment
node 16.20.2
yarn 3.8.2
The text was updated successfully, but these errors were encountered: