6

I have an component that it goBack to the previous page. I use that: this.props.history.goBack(); but I wanna that go back two levels. I have tried a lot of thing as this.props.history.goBack(-2); but I do not achieve that. I am using ReactRouter v4.

How could I do that? Thank you.

JuMoGar
  • 1,740
  • 2
  • 19
  • 46

2 Answers2

15

use this.props.history.go(-2)

as it's described in https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md

menq
  • 391
  • 2
  • 10
  • I have used it but.. `goBack()` do not re-render all page... and `go(-2)` re-render all page... Do you know how solve that? – JuMoGar Jun 06 '17 at 19:40
  • is it the re-render matter ? i mean just control your store's state, and the page will be same as it is. or may you can to use [react-undo](https://github.com/omnidan/redux-undo) – menq Jun 07 '17 at 08:29
  • I am not using Redux. But page may not be reloaded. Other way to solve that? – JuMoGar Jun 07 '17 at 21:50
0

This doesn't have anything to do with Redux. this.props.history.go is using window.history instead of Redux

nliu71
  • 86
  • 5