简体   繁体   English

单击时将表格行重定向到链接

[英]Make a Table Row redirect to a link when it's clicked

Having a tabe with multiple rows I want to redirect to other page when it's clicked.有一个包含多行的标签,我想在单击它时重定向到其他页面。

import React from 'react';
import { Table, Image } from 'semantic-ui-react';
import { Redirect } from 'react-router-dom';

  <Table.Row
      key={myKey}
      onClick={() => <Redirect to={`/another_page/${myKey}}` />}>
      {emptyFirstHeader && (
        <Table.Cell>
          <Image
           stc={blabla}
          />
        </Table.Cell>
      ...
   <Table.Row>

I did it like this but it doesn't do anything.我这样做了,但它什么也没做。

Redirect works with switch and route.重定向适用于交换机和路由。 You can try this:你可以试试这个:

import React from 'react';
import { Table, Image } from 'semantic-ui-react';
import { useHistory } from 'react-router-dom';
const YourFunctionName = () =>{
    const history = useHistory();
    const redirect = (myKey) =>{
        history.push('/another_page/${myKey}`);
     }
     return(
         <Table.Row
      key={myKey}
      onClick={() => redirect(myKey)}>
      {emptyFirstHeader && (
        <Table.Cell>
          <Image
           stc={blabla}
          />
        </Table.Cell>
      ...
     <Table.Row>
   )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM