React router React Router 2.0哈希历史记录-如何删除查询

React router React Router 2.0哈希历史记录-如何删除查询,react-router,React Router,在模块history中,我可以通过以下方式删除查询: import createBrowserHistory from 'history/lib/createHashHistory'; const history = createBrowserHistory({ queryKey: false }); 在react router 2.0中,现在我可以从中获取历史记录: import { Router, Route, hashHistory } from 'react-router'; 如何清

在模块
history
中,我可以通过以下方式删除查询:

import createBrowserHistory from 'history/lib/createHashHistory';
const history = createBrowserHistory({ queryKey: false });
react router 2.0
中,现在我可以从中获取历史记录:

import { Router, Route, hashHistory } from 'react-router';
如何清理url并删除查询?

基于:

从'react Router'导入{Router,useRouterHistory}
从“历史记录”导入{createHashHistory}
//useRouterHistory创建一个可组合的高阶函数
const appHistory=useRouterHistory(createHashHistory)({queryKey:false})

如您所见,
createHashHistory
是从
history
包导入的,因此您必须安装它。或者您可以
从'react router/node\u modules/history'导入{createHashHistory}
(因为
历史
现在是
react router
的正常依赖项)

这非常有效,谢谢

如果有人正在使用browserify(像我一样),代码应该如下所示:

var useRouterHistory=require(“react router/lib/useRouterHistory”);
var createHashHistory=require(“react router/node_modules/history/lib/createHashHistory”);
var-appHistory=useRouterHistory(createHashHistory)({queryKey:false});
//最后将其添加到路由器
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}/>
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}>