Skip to content

Support hashRoot in HashHistoryOptions - #911

Open
thejohnhoffer wants to merge 18 commits into
remix-run:devfrom
thejohnhoffer:main-for-react-router-noslash
Open

Support hashRoot in HashHistoryOptions#911
thejohnhoffer wants to merge 18 commits into
remix-run:devfrom
thejohnhoffer:main-for-react-router-noslash

Conversation

@thejohnhoffer

@thejohnhoffer thejohnhoffer commented Dec 9, 2021

Copy link
Copy Markdown

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 react-router-dom@6.1.1 and use-hash-history.

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

Comment thread packages/history/index.ts Outdated
@thejohnhoffer

thejohnhoffer commented Dec 13, 2021

Copy link
Copy Markdown
Author

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

chaance commented Dec 17, 2021

Copy link
Copy Markdown
Contributor

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 from e8ef3ee to 59580ad Compare December 20, 2021 16:12
@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
@thejohnhoffer
thejohnhoffer force-pushed the main-for-react-router-noslash branch from 46bcb8e to 821d40c Compare December 21, 2021 12:02

@thejohnhoffer thejohnhoffer left a comment

Copy link
Copy Markdown
Author

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.

// const describeGo = canGoWithoutReload ? describe : describe.skip;

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

@thejohnhoffer thejohnhoffer Dec 21, 2021

Copy link
Copy Markdown
Author

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
Copy Markdown
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 thread packages/history/index.ts
Comment on lines +596 to +598
return input.match(/^\.\.\//) ? partial : {
...partial, pathname: input.replace(base, root)
};

@thejohnhoffer thejohnhoffer Dec 21, 2021

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
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

rahulgi commented May 17, 2022

Copy link
Copy Markdown

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

@marcinkowal2015

Copy link
Copy Markdown

+1 for this PR

@hakubo

hakubo commented Jul 7, 2022

Copy link
Copy Markdown

Any chance to move this PR forward?

@hakubo

hakubo commented Jul 12, 2022

Copy link
Copy Markdown

@chaance how could we help moving this forward?

@hakubo

hakubo commented Sep 28, 2022

Copy link
Copy Markdown

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

@Mikilll94

Copy link
Copy Markdown

+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