首页 > 解决方案 > 使用 NavLink 重定向组件 onClick

问题描述

使用带有 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" }} />
    </>
  );
}

标签: reactjsreact-routerreact-router-dom

解决方案


You can simply use the useHistory hook and call history.push(/editPerson/${item.name}) for example to route to that link. If you use react router, you can access the params with useParams, if you declared that in the route definition.

But since this is neither an issue nor has something fundemental to do with the table itself, I would recommend to close this issue. This should be ask in the Forum or on stack overflow. Thank you.


推荐阅读