1.
2.this.state = {
selectedKey: this.props.location.pathname, //选中
openKey: ”” //展开}
3.点击事件
menuClick =e=>{this.setState({selectedKey:e.key})}
4.更新默认状态
componentDidMount(){
const {pathname} = this.props.location;let path = pathname.split(‘/’);
if(pathname.split(‘/’).length>3){path = path[path.length-2];this.setState({openKey:path})}}
5.展开收缩更新状态
onOpenChange = (k) => {
if(k.length>1){this.setState({openKey:k[k.length-1],});}else{this.setState({openKey:”,});}};
原文:https://blog.csdn.net/luckysyy/article/details/83621591