Skip to content

Commit a93b9ba

Browse files
committed
Automatically set active sidebar menu item based on path
1 parent 851242c commit a93b9ba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tools/docs/www/src/side_menu.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import React, { Component, Fragment } from 'react';
2222
import { debounce } from 'throttle-debounce';
23-
import { Link } from 'react-router-dom';
23+
import { Link, withRouter } from 'react-router-dom';
2424
import List from '@material-ui/core/List';
2525
import ListItem from '@material-ui/core/ListItem';
2626
import Collapse from '@material-ui/core/Collapse';
@@ -46,6 +46,16 @@ class MenuBar extends Component {
4646
};
4747
}
4848

49+
componentDidUpdate() {
50+
const history = this.props.history;
51+
const pathname = history.location.pathname;
52+
if ( !pathname.endsWith( this.state.activePkg ) ) {
53+
this.setState({
54+
activePkg: pathname.substring( pathname.indexOf( '@stdlib' ) )
55+
});
56+
}
57+
}
58+
4959
handleDrawerOpen = () => {
5060
this.props.onDrawerChange( true );
5161
}
@@ -281,4 +291,4 @@ class MenuBar extends Component {
281291

282292
// EXPORTS //
283293

284-
export default MenuBar;
294+
export default withRouter( MenuBar );

0 commit comments

Comments
 (0)