Get current page path from react-routers browserHistory object

Viewed 9797

Outside of my components I need to query the current active URL. I'm going to set some classes on the body ( which is outside my react root ) based on this.

First attempt was to use

//Gets an array of class names that I can add to my body tag
getClassNames(window.location.pathname);

But it seems window.location.path isn't updated when React Router navigates. Surprising yes.

So I thought, ok maybe I can get this from browserHistory

import { browserHistory } from 'react-router'

But alas, I can't see a way to read the current page path from here either ( no decent API documentation seems to exist for this object)

Any tips? Seems like a simple problem, and it would be if window.location.pathname stayed in sync with the history object.

2 Answers
Related