redux-history-transitions icon indicating copy to clipboard operation
redux-history-transitions copied to clipboard

How to navigate backwards?

Open avesus opened this issue 9 years ago • 4 comments

How to use standard navigation actions of react-router, i.e. goBack(), replace() etc?

avesus avatar Aug 22 '16 07:08 avesus

How to use replace is described here. Besides push and replace not other methods are currently supported.

johanneslumpe avatar Aug 22 '16 11:08 johanneslumpe

I badly need goBack with great library!

On Monday, August 22, 2016, Johannes Lumpe [email protected] wrote:

How to use replace is described here https://github.com/johanneslumpe/redux-history-transitions#can-i-perform-replace-transitions-instead-of-push. Besides push and replace not other methods are currently supported.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/johanneslumpe/redux-history-transitions/issues/10#issuecomment-241388451, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9MIxgGA9v0HNs00Gsj-6onACkvlHfUks5qiYssgaJpZM4Jpld0 .

Best Regards, Ivan Borisenko

avesus avatar Aug 22 '16 16:08 avesus

I wonder if this'll work. Modify executeTransition like below. Adds an additional check for a key named method in your transition definition. I feel it could be safe cuz I believe neither history API nor react-router consume a method key in any of their operations.

export const executeTransition = history => transitionData => {
  if (transitionData) {
   // const method = transitionData.replace ? 'replace' : 'push';
   const method = transitionData.method || (transitionData.replace ? 'replace' : 'push');
    history[method](transitionData);
  }
};

Example action:

export default {

  goPrevious() {
    return {
      type: PAGE_PREV,
      payload: {
        page: 23
      },
      meta: {
        transition: (prevState, nextState, action) => ({ method: 'goBack' }),
      },
    };
  },
}

jagged3dge avatar Sep 01 '16 00:09 jagged3dge

A goBack and goForward feature would be most welcome.

HZSamir avatar Sep 25 '17 10:09 HZSamir