history icon indicating copy to clipboard operation
history copied to clipboard

V5 Missing hashType="noslash"

Open thejohnhoffer opened this issue 3 years ago • 2 comments

The release of history@5 lost the ability to navigate a HashHistory without a slash in the hash (like #1/2/3 instead of #/1/2/3) due to a missing hashType option to createHashHistory.

After another user asked about the resulting loss of hashType in react-router-dom@6, one maintainer suggested we file in this repository. The solution developed in PR #911 would allow hashRoot="" to replicate the old behavior of hashType="noslash".

The ability to begin hashes with # instead of #/ is not only cosmetic. I am migrating an existing website from vanilla javascript to react, and backwards compatibility of existing URL hash values requires # instead of #/.

thejohnhoffer avatar Dec 10 '21 00:12 thejohnhoffer

With [email protected], the parameter proposed for createHashHistory can take effect immediately, thanks to the prematurely released (as of now unstable) HistoryRouter API.

So, if PR #911 were released with history@next, the changes to history.createHashHistory could directly be used in [email protected] as follows:

<HistoryRouter basename="" history={createHashHistory({
  window, hashRoot: ""
})}>

Here is a short example I've written to integrate react-router-dom with a custom package called use-hash-history that hosts the hashRoot="" feature of PR #911.

thejohnhoffer avatar Dec 12 '21 09:12 thejohnhoffer

@chaance do you see value in this feature? PR #911 has been ready to solve this for some time now.

thejohnhoffer avatar Aug 29 '22 14:08 thejohnhoffer