Fetching contributors…
Cannot retrieve contributors at this time
98 lines (67 sloc) 1.63 KB


FaCC that uses Window.location and Window.history APIs to track page location and re-render on any changes.


import {LocationSensor} from 'libreact/lib/LocationSensor';

<LocationSensor>{(location) =>
  <pre style={{fontFamily: 'monospace'}}>
    {JSON.stringify(location, null, 4)}




Returns location state object with the following signature

interface ILocationSensorState {
  trigger: string;
  state?: any;
  length?: number;
  hash?: string;
  host?: string;
  hostname?: string;
  href?: string;
  origin?: string;
  pathname?: string;
  port?: string;
  protocol?: string;
  search?: string;

withLocation() HOC

Higher order component that injects location prop into your component.

import {withLocation} from 'libreact/lib/LocationSensor';

const MyCompWithLocation = withLocation(MyComp);

Overwrite the inject prop name

const MyCompWithLocation = withLocation(MyComp, 'route');

or merge all props

const MyCompWithLocation = withLocation(MyComp, '');

@withLocation decorator

Stateful component class decorator that injects location prop into your component.

import {withLocation} from 'libreact/lib/LocationSensor';

class MyComp extends Component {


Overwrite prop name

class MyComp extends Component {


or merge all props

class MyComp extends Component {