将React Router Link放在Material UI TableRow上的方法

huangapple go评论71阅读模式
英文:

How to put a React Router Link on a Material UI TableRow

问题

I am trying to put a Link component from React Router Dom on my Material UI TableRow element

<TableRow component={Link as any} to={`/company/${company.id}`} className="clt-row" key={company.id}>

But I keep getting the following error

Property 'to' does not exist on type 'IntrinsicAttributes & TableRowProps & { children?: ReactNode; }'. TS2769

How can I resolve this error?

英文:

I am trying to put a Link component form React Router Dom on my Material UI TableRow element

<TableRow component={Link as any} to={`/company/${company.id}`} className="clt-row" key={company.id}>

But I keep getting the folliwng error

Property 'to' does not exist on type 'IntrinsicAttributes & TableRowProps & { children?: ReactNode; }'.  TS2769

How can I resolve this error?

答案1

得分: 3

行需要单元格。component 属性表示用于行的根节点的组件。默认情况下,它仅为 tr,但可以是任何呈现 tr 作为根节点的组件。

<TableRow>
    <TableCell colSpan={3}> // 或者表格中有多少列
        <Link to={`/company/${company.id}`} className="clt-row" key={company.id} />
    </TableCell>
</TableRow>
英文:

Rows need cells. The component prop represents the component to be used for the root node of the row. It defaults to just a tr but could be any component that renders a tr as a root node.

<TableRow>
    <TableCell colSpan={3}> // or however many columns are in your table
        <Link to={`/company/${company.id}`} className="clt-row" key={company.id} />
    </TableCell>
</TableRow>

huangapple
  • 本文由 发表于 2020年1月6日 15:18:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608100.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定