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

后端 未结 6 2225
[愿得一人]
[愿得一人] 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 18:07

    you can set the paths of the link as keys on each Menu.Item . then selectedKeys={this.props.location.pathname}

    
      
        Link to={item.path}>{item.name}
      
      {menulist}
    
    

    Item would be set active according to the current path. i added [] and trailing comma because selectedKeys accepts array while this.props.location.pathname is a String. i just code as hobby so idont know if its acceptable.

提交回复
热议问题