带有样式组件的样式链接

Posted

技术标签:

【中文标题】带有样式组件的样式链接【英文标题】:Style Link with styled components 【发布时间】:2020-03-14 23:08:59 【问题描述】:

我在 TypeScript React 应用程序中使用 styled-components,并且在它上面有一个路由器。

是否可以使用带样式的组件对 react-router-dom 中的 Link 元素进行样式设置?

可能是这样的:

  const HeaderLink = styled.Link`
    background-color: hotpink;
  `

【问题讨论】:

【参考方案1】:

有可能,只需将Link 作为参数传递给styled 函数:

const StyledLink = styled(Link)`
   color: green;
`;

【讨论】:

记得import Link from 'react-router-dom'

以上是关于带有样式组件的样式链接的主要内容,如果未能解决你的问题,请参考以下文章