I am having trouble getting this to work. I'm trying to get the material ui leftNav to work with react router and redux with nav going through the store and router. This was close, but didn't get all the way to the menu item.
TypeError: Cannot read property 'isActive' of undefined
I was also referring to these examples: https://github.com/callemall/material-ui/blob/master/docs/src/app/components/app-left-nav.jsx
http://codetheory.in/react-integrating-routing-to-material-uis-left-nav-or-other-components/
Here is the component I'm working on. I started with react-redux-universal-hot-example. This component is going into the App component.
import React, { Component } from 'react';
import LeftNav from 'material-ui/lib/left-nav';
import RaisedButton from 'material-ui/lib/raised-button';
const menuItems = [
{ route: '/widgets', text: 'Widgets' },
{ route: 'survey', text: 'Survey' },
{ route: 'about', text: 'About' }
];
export default class MaterialLeftNav extends Component {
static propTypes = {
history: React.PropTypes.object
}
static contextTypes = {
location: React.PropTypes.object,
history: React.PropTypes.object
}
contructor(props) {
super(props);
}
_onLeftNavChange(e, key, payload) {
this.props.history.pushState(null, payload.route);
}
_handleTouchTap() {
this.refs.leftNav.toggle();
}
_getSelectedIndex() {
let currentItem;
for (let i = menuItems.length - 1; i >= 0; i--) {
currentItem = menuItems[i];
if (currentItem.route && this.props.history.isActive(currentItem.route)) return i;
}
}
render() {
return (
<div>
<LeftNav
ref="leftNav"
docked
menuItems={menuItems}
selectedIndex={this._getSelectedIndex()}
onChange={this._onLeftNavChange}
/>
<RaisedButton label="Toggle Menu" primary onTouchTap={this._handleTouchTap} />
</div>
);
}
}
This ended up being a really verbose way to get this done, mostly because I'm learning how to code. There was a callback in the onChange that included the variables needed to specify the path. I still needed access to history in the way described here, but getting the path passed from the menu turned out to be much more straightforward.
There were a few other things in here as well that I'm leaving in for my own future reference and the off chance that some other noob like myself stumbles across this. The first was passing the path down to be able to use in the app bar and the second was the passing down of the theme file to access the color variables. The last one was the passing down of the window size info from the state, which was being used here to dock the left nave on screens bigger than medium.