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

Support hashRoot in HashHistoryOptions #911

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from

Conversation

thejohnhoffer
Copy link

@thejohnhoffer thejohnhoffer commented Dec 9, 2021

Closes issue #912

Calling createHashHistory with hashRoot="" replicates the lost hashType="noslash" from history@4. This PR is to address issue #8459 and issue #7703 of react-router.

Update

Until this PR is merged, this is still possible with [email protected] and use-hash-history.

I accomplish this with a function to convert between history.location and window.location

@thejohnhoffer
Copy link
Author

thejohnhoffer commented Dec 13, 2021

As it stands now, I'm currently using this solution with a fork of history.

UPDATE:
I'm currently using use-hash-history as a stand-in for this PR, following this template. It should be more maintainable than the fork.

@chaance
Copy link
Contributor

chaance commented Dec 17, 2021

Hey @thejohnhoffer, thanks for this! A couple of quick things:

  • It looks like this PR is only showing your change to your fork's docs. Can you fix that for us?
  • Can you set the base branch to dev? We merge code changes there (I should probably update that default in GitHub)

Thanks!

@thejohnhoffer

This comment has been minimized.

@chaance chaance changed the base branch from main to dev December 17, 2021 23:35
@thejohnhoffer thejohnhoffer force-pushed the main-for-react-router-noslash branch 2 times, most recently from 657fc44 to 46bcb8e Compare December 20, 2021 19:20
Copy link
Author

@thejohnhoffer thejohnhoffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the tests, this is a non-breaking change with added support of hashRoot: "" as a replacement for the lost feature of hashType: "noslash". For my purposes, this PR is now ready to merge.

@@ -21,12 +21,19 @@ import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.j
// const canGoWithoutReload = window.navigator.userAgent.indexOf('Firefox') === -1;
// const describeGo = canGoWithoutReload ? describe : describe.skip;

describe('a hash history', () => {
export const testHashHistory = (initialRoot, options) => {
Copy link
Author

@thejohnhoffer thejohnhoffer Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can test both createHashHistory() and createHashHistory({hashRoot: ""})

Comment on lines +32 to +35
const { hashRoot = "/" } = options || {};
const historyHref = createPath(history.location);
const windowHref = window.location.hash.substr(1);
expect(historyHref.replace(/^\//, hashRoot)).toEqual(windowHref);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves issue #918

Comment on lines +596 to +598
return input.match(/^\.\.\//) ? partial : {
...partial, pathname: input.replace(base, root)
};
Copy link
Author

@thejohnhoffer thejohnhoffer Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interchange hashRoot and '/' (unless the pathname starts with "../")

This solves issue #912.

@thejohnhoffer
Copy link
Author

According to the tests, this is a non-breaking change with added support of hashRoot: "" as a replacement for the lost feature of hashType: "noslash". For my purposes, this PR is now ready to merge.

I'm happy to make any changes the maintainers decide should be made on this before merging. @chaance hopefully this PR is clearer to follow now, at only 35 lines of code (including tests).

@thejohnhoffer
Copy link
Author

Hi @chaance -- I've again tested that the new and old tests all pass. My own alternative to this PR, use-hash-history, has a few users. I'm happy to continue maintaining my own package, but merging this PR would simplify the dependency tree of anyone who needs that feature.

I'm happy to simplify, remove, or re-write some of the tests I've created for this PR.

@rahulgi
Copy link

rahulgi commented May 17, 2022

Adding a +1 to request that this PR gets merged, thanks for creating this, @thejohnhoffer!

@marcinkowal2015
Copy link

+1 for this PR

@hakubo
Copy link

hakubo commented Jul 7, 2022

Any chance to move this PR forward?

@hakubo
Copy link

hakubo commented Jul 12, 2022

@chaance how could we help moving this forward?

@hakubo
Copy link

hakubo commented Sep 28, 2022

@chaance "This branch has no conflicts with the base branch" - anything we could do?

@Mikilll94
Copy link

+1 for merging this PR

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

Successfully merging this pull request may close these issues.

6 participants