如何获得到达路由器的当前路由。在 react 路由器中,可以通过参数获得它吗?
文档目前没有显示如何执行此操作的示例。
最佳答案
或者,使用 useLocation
钩子(Hook)(自 1.3.0 起):
import { useLocation } from "@reach/router"
const useAnalytics = () => {
const location = useLocation()
useEffect(() => {
ga.send(['pageview', location.pathname])
}, [])
}
引用:https://reach.tech/router/api/useLocation
关于reactjs - @reach/路由器 : how to get the current route/page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56838072/