样式化组件 Link

Style Link with styled components

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

是否可以使用带样式的组件为 react-router-dom 中的 Link 元素添加样式?

可能是这样的:

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

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

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