pbeshai / react-url-query

A library for managing state through query parameters in the URL in React
https://pbeshai.github.io/react-url-query
MIT License
195 stars 38 forks source link

Using react-router v5 #65

Closed antonio-goncalves-unp closed 5 years ago

antonio-goncalves-unp commented 5 years ago

Using: react-url-query: v1.4.0 react-router-dom: v5.0.1

I was trying to following this example but using v5 of react-router,

React Router v4

import { RouterToUrlQuery } from 'react-url-query';
import Router from 'react-router/BrowserRouter';

ReactDOM.render(
  <Router>
    <RouterToUrlQuery>
      <App />
    </RouterToUrlQuery>
  </Router>,
  document.getElementById('root')
);

But it gives me this error

"No history provided to react-url-query. Please provide one via configureUrlQuery."

I also tried doing this

Not using React Router. If you're not using react-router, you'll need to instantiate the history yourself manually:

import { configureUrlQuery } from 'react-url-query';
import createHistory from 'history/createBrowserHistory';
const history = createHistory();

configureUrlQuery({ history });

But it resulted in an unexpected behaviour

How to use this library with react-router v5?

Thanks in advance

pbeshai commented 5 years ago

See #64 or the updated README for v1.5.0.

import { __RouterContext as RouterContext } from 'react-router';
// ...
<RouterToUrlQuery routerContext={RouterContext}> 
  // ...
</RouterToUrlQuery>