Search code examples
reactjsonclickantd

antd Table onRow onClick to another component


I have an antd table displaying my data. However, how would I ensure that when the user clicks on a specific row, it will redirect him to a new component named "ViewLog" with the row data?

Code that I provided below doesn't work:

 <Table bordered
        className="components-table-demo-nested"
        onRow={(i) => ({
          onClick: (e) => {
              return <Link to={"/admin/ViewLog"}></Link>;
            },
          })}
        columns={columns}
        expandable={{ expandedRowRender }}
        dataSource={data}
        size="small"
      />

Solution

  • Edit your code as following and your code might work:

    onRow={(i) => ({
        onClick: (e) => 
            history.push('/admin/ViewLog')
    })}