redux-router-kit icon indicating copy to clipboard operation
redux-router-kit copied to clipboard

Allow switching 'history' implementation.

Open xdave opened this issue 8 years ago • 4 comments

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)

xdave avatar May 31 '17 01:05 xdave

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!

jdeal avatar May 31 '17 17:05 jdeal

Sure, I'll take a look this evening.

xdave avatar May 31 '17 21:05 xdave

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(-)

xdave avatar Jun 01 '17 01:06 xdave

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

jdeal avatar Jun 06 '17 21:06 jdeal