Skip to content

Commit

Permalink
Only push new location if it actualy changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
FredTingaud authored and Frederic Tingaud committed Jun 11, 2017
1 parent 4e028e7 commit 5742164
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ class App extends Component {
constructor(props) {
super(props);
this.state = {
location: null
location: null,
prevlocation: null
}
}
componentDidUpdate(prevProps, prevState) {
if (this.state.location) {
this.setState({ location: null });
if (this.state.location !== this.state.prevlocation) {
this.setState({
prevlocation: this.state.location
});
}
}
redirect() {
if (this.state.location) {
if (this.state.location !== this.state.prevlocation) {
return (
<Redirect push to={'/' + this.state.location} />
);
Expand Down

0 comments on commit 5742164

Please sign in to comment.