I recently use ES6 style to develop React project with react-router(2.0.0-rc5). So I used the context.router instead of history by reading the guide and CHANGELOG.
However, some error happened.
First, the this.context.router is undefined, and I found answer in rackt/react-router#975 and rackt/react-router#1059 .
Second, some warning appeared in console:
Warning: Failed Context Types: Invalid context `router` of type `object` supplied to `Banner`, expected `function`. Check the render method of `Home`.
and I fix it by react-bootstrap/react-router-bootstrap#91
Could you add some instruction such as ES6 solution for these problems to docs, please ? (⊙v⊙)
And this is exactly why we don't do support on the issue tracker – all of those instructions are old, and pertain to stuff that's like 2 major releases old, or older.
@taion anyway, thanks
Use contextTypes like this:
class Index extends Component {
static contextTypes = {
router: PropTypes.object.isRequired
};
//...
}
using ES7 property initialisers need to install babel-plugin-transform-class-properties
Most helpful comment
Use contextTypes like this: