I use webpack
, ES6
, react-router
library and Link
component for my links. I want to "transit" with parent div of link element, but when I click on div I get error:
Uncaught TypeError: Cannot read property 'transitionTo' of undefined
I followed this and this thread.
NavBar.jsx
var React = require('react');
var Router = require('react-router');
var { Route, DefaultRoute, RouteHandler, Link } = Router;
var CustomersIcon = require("./icons").CustomersIcon;
export class NavBar extends React.Component {
constructor(props, context) {
super(props, context);
}
_openLink() {
this.context.router.transitionTo('/');
}
render() {
return (
<div className="menu-item-wrapper" onClick={this._openLink.bind(this)}>
<CustomersIcon />
<Link to="/customers" activeClassName="active" ref="customersLink">Customers</Link>
</div>
);
}
}
NavBar.contextTypes = {
router: function contextType() {
return React.PropTypes.func.isRequired;
}
};