Antd react router navigation changes to the appropriate page option as the page jumps to the menu bar

use antd component react frame single page router my page column jumps want to achieve the left menu bar navigation index also changes to the corresponding page options, how do you achieve this function! Just give me some ideas picture description

Mar.03,2021

judge the selected key based on url

render() {
    const pathName = hashHistory.getCurrentLocation().pathname;
    return (
        <Menu selectedKeys={[pathName]} >
        ...
        </Menu>
    );
}

if you use the Menu component of antd, you already have this feature.


have brothers solved it? Share!


directly gives you a Demo. DvaInitial , and the menu is implemented using antd's menu.


there is an idea that, if it is antd, your menu bar Sider component should have a method to set selectedKeys according to the time you click, so when you jump or move forward or backward within the page, you can call the method to set selectedKeys in the componentWillReceiveProps status method to make the menu highlight correspond to the jump on the page

.
Menu