react-router使用hashHistory

#1

如题:http://localhost:9090/#/businessList/TEST?_k=5weflx
后面的跟的一个参数是什么?有什么用么?

#2

看这里
https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#what-is-that-_kckuvup-junk-in-the-url

#3

这个参数可以通过router组件的props.location.key取到,重复点击链接时key会变化。

比如在导航菜单中,当前选中的菜单路由是businessList/menu1,继续点击businessList/menu1时,可以通过key的变化来刷新页面。

#4

没明白。这里面好像没说?_k=5weflx的作用吧。

#5

那能去掉么_k=5weflx?

#6

文档里边有提到怎么去掉

#7
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} />
1 Like
#8

#9

谢谢

#10

但是我把后面那串去掉后 我的路由不能用state传参了 应该怎么办?