this.setState({
redirect: true
})
componentWillReceiveProps(nextProps) {
if (nextProps.keydown.event) {
const key = nextProps.keydown.event.which;
const location = nextProps.location.pathname;
const history = nextProps.history;
if (key === 39 && location === '/index') {
this.timeOut(history, '/index/loc1');
} else if (key === 39 && location === '/index/loc1') {
this.timeOut(history, '/index/loc2');
} else if (key === 37 && location === '/index/loc1') {
this.timeOut(history, '/index');
} else if (key === 37 && location === '/index/loc2') {
this.timeOut(history, '/index/loc1');
}
}
}
timeOut = (history, loc) => setTimeout(() => history.push(loc), 100);
if (k === 37 && location=== '/index/loc1') {
...
} else if (k === 37 && location=== '/index/loc2'){
...
}