react-router-component icon indicating copy to clipboard operation
react-router-component copied to clipboard

Make popstate behave

Open yoshuawuyts opened this issue 11 years ago • 0 comments

It appears that react-router-component listens to onpopstate() and triggers itself, causing a conflict with my current setup.

When clicking a navigation element in my application, the path store gets updated and through a change-listener my router triggers a re-render. If I hit the back button, I'd like to update the path store with window.location.pathname, and through a change-listener trigger a re-render on my router.

How can I make react-router-component stop triggering on onpopstate() events?

edit: I want to make this work:

function componentDidMount() {
  // update the state with the new url when the store updates
  pathStore.on('update', updateUrl.bind(this));
  // listen to changes to 'pop state' and update the store accordingly
  window.onpopstate = function() {
    dispatcher.dispatch('path_update', window.location.pathname);
  };
}

yoshuawuyts avatar Jun 12 '14 12:06 yoshuawuyts