How to use normal anchor links with react-router

The problem with anchor links is that react-router’s default is to use the hash in the URL to maintain state. Fortunately, you can swap out the default behaviour for something else, as per the Location documentation. In your case you’d probably want to try out “clean URLs” using the HistoryLocation object, which means react-router won’t use the URL hash. Try it out like this:

Router.run(routes, Router.HistoryLocation, function (Handler) {
  React.render(<Handler/>, document.body);
});

Leave a Comment