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

Allow switching 'history' implementation. #2

Open
xdave opened this issue May 31, 2017 · 4 comments
Open

Allow switching 'history' implementation. #2

xdave opened this issue May 31, 2017 · 4 comments

Comments

@xdave
Copy link

xdave commented May 31, 2017

I have apps that only use the hash for route changes (using react-router). Usually, I can switch between them by importing a different history implementation.

For example, instead of:

import createHistory from 'history/lib/createBrowserHistory';

(it appears you are using the old history version 2.0.1)

I use:

import createHistory from 'history/createHashHistory';

(using [email protected] https://github.com/ReactTraining/history)

@jdeal
Copy link
Contributor

jdeal commented May 31, 2017

Yeah, really it should allow history as a prop. I kind of meant to do that but never got to it. Not sure when I'll get to that (actually on vacation now). If love a PR for that if you want to give it a try!

@xdave
Copy link
Author

xdave commented May 31, 2017

Sure, I'll take a look this evening.

@xdave
Copy link
Author

xdave commented Jun 1, 2017

Ug, there's lots of API changes between those history versions. I'm a bit fuzzy as to what the History component is doing and how it works.

history 2.0.1 => history 4.6.1:
101 files changed, 7582 insertions(+), 4147 deletions(-)

@jdeal
Copy link
Contributor

jdeal commented Jun 6, 2017

@xdave Yeah, it looks like they got rid of listenBefore. This affects the History component's ability to cancel routing. The History component allows setting the route via the url prop, and it also allows listening to external route changes through the onChange prop. When the onChange callback is called, the same url is expected to be fed back through the prop. Otherwise, it's assumed that the route was cancelled. It looks like history.block is the new way to cancel transitions, but it doesn't support a callback for cancellation, so rather than dynamically creating a callback, we'll have to check for cancellation right after onChange is called. There's one test that validates the cancellation behavior, so we'd just have to make sure that still passes.

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

No branches or pull requests

2 participants