Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Router v2.4 { queryKey: false } no longer works

I've updated react-router to the latest version - 2.4.1
I use hashHistory in my app

import { Router, useRouterHistory } from 'react-router'
import { createHashHistory } from 'history'
// useRouterHistory creates a composable higher-order function
const appHistory = useRouterHistory(createHashHistory)({ queryKey: false })
<Router history={appHistory}/>

And now I'm getting an error

Warning: Using { queryKey: false } no longer works. 
Instead, just don't use location state if you don't want a key in your URL query string

How can I fix this?

I don't want additional query key to appear in url. I expect the same behaviour as from angular router or backbone router.

like image 280
Dmitriy Nevzorov Avatar asked Jun 02 '16 11:06

Dmitriy Nevzorov


1 Answers

This warning does not actually originate from React Router but the history module it uses. In fact, the latest version (3.0.0, May 30 2016) doesn’t work at all with React Router:

Uncaught Invariant Violation: You have provided a history object created with history v3.x. This version of React Router is not compatible with v3 history objects. Please use history v2.x instead.

This warning is present as of v2.5.1 (Jun 24 2016).

So the easiest solution is to just use the same version React Router uses, courtesy of its package.json:

"history": "^2.0.1"

After that, the queryKey option works as expected.

like image 103
Daniel B Avatar answered Oct 12 '22 14:10

Daniel B