0
votes

I am using React-router 3.2.0 so I have a button in the application on which I called goBack function of hashHistory as below

Router.hashHistory.goBack();

I works fine but I need to add some condition before it called. So my problem is like if I move between 3 links

  1. Home
  2. Dashboard
  3. Settings

Initially it will be on Home then I moved to Dashboard then Settings. Now I clicked on button on which I called goBack() function at that time current history location is Settings it moved to Dashboard then Home after reaching at Home there is no such history locations exist.

So this is I need to check is there any history location still exist or not. Something like

if(/*history exist*/){
 call goBack();
} else {
 //do my stuff
}

Is there any way to do that in react-router 3.2.0 version ?

1
Maybe you can find here your answer ;) github.com/ReactTraining/react-router/issues/408Paolo Dell'Aguzzo

1 Answers

0
votes

The history object in react-router has a length property indicating how many entries are in the stack.

if (history.length !== 0) {
 goBack();
} else {
 // do my stuff
}