React-router: Is there any way to override context.router.goBack?

Created on 17 Jun 2016  路  1Comment  路  Source: ReactTraining/react-router

Most helpful comment

Solved!

import { createHistory } from 'history';

const history = useRouterHistory(createHistory)();

Object.assign(history, {
  goSmartBack: () => {
    if (window.history.length >= 1 && window.history.length <= 2) {
      history.push('/');
    } else {
      history.goBack();
    }
  },
});

>All comments

Solved!

import { createHistory } from 'history';

const history = useRouterHistory(createHistory)();

Object.assign(history, {
  goSmartBack: () => {
    if (window.history.length >= 1 && window.history.length <= 2) {
      history.push('/');
    } else {
      history.goBack();
    }
  },
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ackvf picture ackvf  路  3Comments

jzimmek picture jzimmek  路  3Comments

winkler1 picture winkler1  路  3Comments

Radivarig picture Radivarig  路  3Comments

ryansobol picture ryansobol  路  3Comments