Skip to content
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

[Feature]: Support basename="" for HashRouter #8459

Closed
thejohnhoffer opened this issue Dec 9, 2021 · 1 comment
Closed

[Feature]: Support basename="" for HashRouter #8459

thejohnhoffer opened this issue Dec 9, 2021 · 1 comment
Labels

Comments

@thejohnhoffer
Copy link

thejohnhoffer commented Dec 9, 2021

What is the new or updated feature that you are suggesting?

For the HashRouter, it should be possible to start the location.hash with # instead of #/. To this end, I request the ability to serialize relative location instead of absolute location.

PR #8460 supports writing the relative path in the URL, configured to take effect when the Router basename property is given as "", instead of the default of "/".

UPDATE:

This is now possible with [email protected] and use-hash-history. I hope it will be soon available with an upcoming release of history through PR #911.

Examples

When using HashRouter, the default basename is "/". This results in urls like this:

example.com/#/
example.com/#/abc
example.com/#/1/2/3

After PR #8460, using <HashRouter basename=""> results in urls like this:

example.com/#
example.com/#abc
example.com/#1/2/3

I've created a codepen to compare the current behavior of <HashRouter basename=""> for the current V6 of react-router-dom and my PR #8460

Why should this feature be included?

In react-router-dom@v5, it was once possible to append directly after # with hashType="noslash". The hashType property of createHashHistory was available in history@4, but lost in history@5, so the additional configuration it afforded the HashRouter was removed in react-router-dom@6 with no replacement.

In react-router-dom@6, there is no possibility of hashType="noslash", so I propose we implement it whenever the user provides basename="". The other missing hashType of hashType="hashbang" could also supported with basename="!#", but that might be a separate issue.

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
Copy link
Author

thejohnhoffer commented Dec 10, 2021

This could now be addressed with PR #8463 and remix-run/history PR #911. My previous PR #8460 was closed, but I'm hopeful the new PRs will also be considered.

UPDATE:

This is now possible with [email protected] and use-hash-history. I hope it will be soon available with an upcoming release of history through PR #911.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants