ElemeFE / ElemeFE/element-react

Component Menu not display correct current active Menu Item when using this.props.history.push

Open
#778 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.8k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

I use component Menu with React-router v4 and its Hight order component `withRouter`. When I put something like `this.props.history()` in the Menu's prop `onSelect`, the current active Menu item displays incorrectly, that's to say, the prop `activeIndex` changes incorrectly.

so I searched code in the library, I found that in Menu.jsx

````
componentWillReceiveProps(props: Object) {
if (props.defaultActive != this.props.defaultActive || props.defaultActive != this.state.activeIndex) {
this.defaultActiveChanged(props.defaultActive);
}

if (props.defaultOpeneds != this.props.defaultOpeneds) {
this.defaultOpenedsChanged(props.defaultOpeneds);
}
}
````

I removed `props.defaultActive != this.state.activeIndex` in the first if condition, everything is good.

So, I want the owner to check if there is something wrong, or explain how To do to navigate path with react router v4 with Menu component.

Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.