Jacob Goh Jacob Goh - 3 months ago 13
React JSX Question

react-router in browser. "hashHistory is not defined"

I am trying to use React-router in browser without using NPM

https://codepen.io/jacobgoh101/pen/XjAmAg?editors=0011

I have added

let Router = window.ReactRouter;
let RouteHandler = Router.RouteHandler;
let Route = Router.Route;
let DefaultRoute = Router.DefaultRoute;


as suggested in this post.

But still, I receive this error


Uncaught ReferenceError: hashHistory is not defined


Any idea how to fix this ? Thanks !

Answer

The error clearly mentions it. You did not define hashHistory. so import it from react-router as

let hashHistory = Router.hashHistory;

All imports

let Router = window.ReactRouter;
let RouteHandler = Router.RouteHandler;
let Route = Router.Route;
let DefaultRoute = Router.DefaultRoute;
let hashHistory = Router.hashHistory;