How do I populate context so that history is not undefined when using tags in react-router?
The error I am getting is : Uncaught TypeError: Cannot read property 'pushState' of undefined
on function Link.handleClick at line:
if (allowTransition) this.context.history.pushState(this.props.state, this.props.to, this.props.query);
I'm using react-router 1.0.0-rc1.
The top level routes works fine. I get to my main component, which displays a link to "signup". This link should bring me to the child component.
My sample app looks like this:
Routes.jsx
============
var React = require('react');
var ReactRouter = require('react-router');
var createBrowserHistory = require('history/lib/createBrowserHistory');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Main = require('./main/main');
var Signup = require('./signup/signup');
module.exports = (
<Router history ={createBrowserHistory()}>
<Route path="/app" component={Main}>
<Route path="/signup" component={Signup}></Route>
</Route>
</Router>
);
Main.jsx
===============
var ReactRouter = require('react-router');
var Link = ReactRouter.Link;
module.exports = React.createClass({
render: function(){
return <div><Link to="/signup">signup</Link></div>
}
})
this.props.history.push('/', null);
and check it bythis.props.history
YOu should be get to see alsopush
andreplace
bothfunction – MD Ashik