Reputation: 54551
I'm trying to use the React Route component to specify my routing configuration. This is basically what I'm doing:
ReactDOM.render(
<ReactRouter.Router>
<ReactRouter.Route path="/" component={App}>
</ReactRouter.Route>
</ReactRouter.Router>,
document.querySelector("#container")
);
The above results in a Type Error:
TypeError: history is undefined
Everything is inside a text/babel
script tag which resides in the body
of the html document. I'm importing ReactRouter
by adding the following script tag to the head
of the document:
<script src="https://npmcdn.com/react-router/umd/ReactRouter.js"></script>
My application works fine when not using ReactRouter
. That is, the following code doesn't result in a Type Error:
ReactDOM.render(
<App/>,
document.querySelector("#container")
);
Am I using the component wrong? What am I missing?
Upvotes: 1
Views: 356
Reputation: 3319
You have to provide history
for ReactRouter
, it can be browserHistory
or hashHistory
depends on your structure. See more information in documentation
ReactDOM.render(
<ReactRouter.Router history={ReactRouter.hashHistory}>
<ReactRouter.Route path="/" component={App}>
</ReactRouter.Route>
</ReactRouter.Router>,
document.querySelector("#container")
);
Upvotes: 1
Reputation: 7428
Try adding <ReactRouter.Router history={ReactRouter.hashHistory}>
Upvotes: 1