Answer the question
In order to leave comments, you need to log in
How to close the menu when changing the address?
When changing the page, I want to close the menu.
componentDidUpdate(prevProps, prevState, snapshot) {
if (this.state.menuMobile) {
if (this.props.location.pathname !== this.props.history.location.pathname) {
this.setState({
menuMobile: false
})
}
}
}
<NavLink to="/" >
Answer the question
In order to leave comments, you need to log in
Why are this.props.location.pathname and this.props.history.location.pathname suddenly equal?
componentDidUpdate(prevProps) {
if (
prevProps.location.pathname !== this.props.location.pathname &&
this.state.menuMobile
) {
this.setState({ menuMobile: false });
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question