Я хочу изменить URL-адрес с помощью «history.push».
, но есть ввод:
("/main")
, но я не хочу ставить ключ на «MainPage» изScreen
.
Как мне поступить?
class Screen extends Component {
componentDidMount() {
this.div.focus();
}
handleKeyDown = e => {
if (e.key === "Enter") {
this.props.history.push("/main");
}
};
render() {
return (
<div
ref={ref => (this.div = ref)}
tabIndex="0"
onKeyDown={e => this.handleKeyDown(e)}
>
<Image />
</div>
);
}
}
export default withRouter(Screen);