【问题标题】:useHistory is not exported in version 6.0.0-beta.0?在 6.0.0-beta.0 版本中没有导出 useHistory?
【发布时间】:2021-09-15 04:14:44
【问题描述】:
"react-router": "^6.0.0-beta.0",
"react-router-dom": "^6.0.0-beta.0",

Material UI 'Devias Material Kit Pro' 模板有这个版本,并且 useHistory 不起作用,是否还有其他名称不同的属性相同?我使用了 Navigation.push (history.push) 和 useNavigate,但它不起作用。

useHistory 仅适用于 5.2.0 版?

useHistory 错误

【问题讨论】:

    标签: reactjs typescript switch-statement version react-router-dom


    【解决方案1】:

    截至react-router@6.x,此功能已移至useNavigate 挂钩。所以history.push/history.replace 的替换现在看起来像:

    const { useNavigate } from 'react-router-dom'
    
    ...
        const navigate = useNavigate()
        ...
        navigate({ pathname: './some/path' }) // instead of navigate.push
        // or
        navigate({ pathname: './some/path' }, { replace: true }) // navigate.replace
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 2022-07-23
      • 1970-01-01
      • 2019-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多