首页 > 解决方案 > 如何在 Material UI TableRow 上放置一个 React Router Link

问题描述

我正在尝试在我的Material UI TableRow元素上放置一个Link组件表单React Router Dom

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

但我不断收到以下错误

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

如何解决此错误?

标签: reactjstypescriptmaterial-uireact-router-dom

解决方案


行需要单元格。componentprop 表示要用于行的根节点的组件。它默认只是 atr但可以是任何将 a 呈现tr为根节点的组件。

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


推荐阅读