Reputation:
In the module history
, I could remove the query by:
import createBrowserHistory from 'history/lib/createHashHistory';
const history = createBrowserHistory({ queryKey: false });
In react-router 2.0
now that I am getting history from it:
import { Router, Route, hashHistory } from 'react-router';
How can I clean up the url and remove the query?
Upvotes: 2
Views: 6427
Reputation: 1688
This works great, thanks.
In case someone is working with browserify (like I am), the code should look like this:
var useRouterHistory = require("react-router/lib/useRouterHistory");
var createHashHistory = require("react-router/node_modules/history/lib/createHashHistory");
var appHistory = useRouterHistory(createHashHistory)({ queryKey: false });
// finally add it to the router
<Router history={appHistory}>
Upvotes: 0
Reputation: 1795
Based on react-router v2.0.0 Upgrade Guide:
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}/>
As you see, createHashHistory
is imported from history
package, so you have to install it. Or you can import { createHashHistory } from 'react-router/node_modules/history'
(as history
is now a normal dependency of react-router
)
Upvotes: 2