react-router+antD/ How to highlight a menu item when press back/forward button?

后端 未结 6 2231
[愿得一人]
[愿得一人] 2021-02-12 17:54

I create a menu and want to highlight the item which i choose,and i did it. But when i press back/forward button,the menu item don\'t highlight. What should i do?

I ha

6条回答
  •  醉酒成梦
    2021-02-12 17:59

    I could come up with a solution using WithRouter

    import React,{ Component } from 'react';
    import { NavLink, withRouter } from 'react-router-dom';
    import { Layout, Menu, Icon } from 'antd';
    import PropTypes from 'prop-types';
    
    const { Sider } = Layout;
    
    class SideMenu extends Component{
    
      static propTypes = {
        location: PropTypes.object.isRequired
      }
    
      render() {
        const { location } = this.props;
        return (
            
    
              
    Home Applications Notifications ) } } export default withRouter(SideMenu);

提交回复
热议问题