在模块history
中,我可以通过以下方式删除查询:
import createBrowserHistory from 'history/lib/createHashHistory';
const history = createBrowserHistory({ queryKey: false });
现在react-router 2.0
我正在从中获取历史记录:
import { Router, Route, hashHistory } from 'react-router';
如何清理网址并删除查询?
答案 0 :(得分:2)
基于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}/>
如您所见,createHashHistory
是从history
包导入的,因此您必须安装它。或者您可以import { createHashHistory } from 'react-router/node_modules/history'
(因为history
现在是react-router
的正常依赖关系)
答案 1 :(得分:0)
这很有效,谢谢。
如果有人使用browserify(就像我一样),代码应如下所示:
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}>