zapier / redux-router-kit

Routing tools for React+Redux
MIT License
51 stars 8 forks source link

Allow switching 'history' implementation. #2

Open xdave opened 7 years ago

xdave commented 7 years ago

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 history@4.6.1 https://github.com/ReactTraining/history)

jdeal commented 7 years ago

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 commented 7 years ago

Sure, I'll take a look this evening.

xdave commented 7 years ago

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 commented 7 years ago

@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.