【问题标题】:re-direct component onClick with NavLink使用 NavLink 重定向组件 onClick
【发布时间】:2020-03-11 12:33:01
【问题描述】:

使用带有 React Hooks 的 Material Table 我的愿望是重定向 onClick。目前 onClick 没有响应。

材质表组件

actions={[
        {
          onClick: (items) => {
           /*
             I want to re-direct to another route("/editperson") + 
             component(EditPerson.tsx) and send it props from this component
           */
          }
        }
      ]}

NavigateToEditPerson.tsx

function NavigateToEditPerson() {
  return (
    <>
      <NavLink to={{ pathname: "/editPerson" }} />
    </>
  );
}

【问题讨论】:

    标签: reactjs react-router react-router-dom


    【解决方案1】:

    您可以简单地使用 useHistory 钩子并调用 history.push(/editPerson/${item.name}) 例如路由到该链接。如果您使用 react 路由器,则可以使用 useParams 访问参数,前提是您在路由定义中声明了该参数。

    但由于这既不是问题,也与表本身没有根本关系,我建议关闭此问题。这应该在论坛或堆栈溢出时询问。谢谢。

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2014-05-21
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 2023-01-28
      相关资源
      最近更新 更多