简体   繁体   中英

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>
   )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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