【问题标题】:Using props in an a href to link to an external link - React在 a href 中使用道具链接到外部链接 - React
【发布时间】:2020-12-30 11:50:13
【问题描述】:

我正在尝试使用路径道具将整张卡片链接到外部网站的投资组合部分。

CardItem 组件:

function CardItem(props) {
  return (
    <>
      <li className='cards_item'>
        <a href= {props.path} className="cards_item_link" target="_blank" rel="noopener noreffer">
          <figure className='cards_item_pic-wrap' data-category={props.label}>
            <img
              className='cards_item_img'
              alt='Portfolio Pictures'
              src={props.src}
              path={props.path}
            />
          </figure>
          <div className='cards_item_info'>
            <h5 className='cards_item_text'>{props.text}</h5>
          </div>
        </a>
      </li>
    </>
  );
}

我传递的 CardItem 是:


<CardItem
  src=image/magic.png"
  text="Magic App"
  label="iOs"
  path="https://bigassmessage.com/"
/>

I'm pretty sure it's the href linking but not sure how to fix with the correct styling. I tried backticks and ${props.path} but it just keeps me on the same page without properly taking me to a the correct page.

New to react so don't be too harsh.

【问题讨论】:

    标签: reactjs jsx react-props


    【解决方案1】:

    所以我从您的代码创建了一个代码沙箱,它似乎工作正常。我看到的唯一一件事是你拼写了 noreferrer 错误,你应该把图像放在公用文件夹中,然后用“/image/magic.png”链接到它们。 / 告诉反应它在公共文件夹中。这是代码沙箱的链接。 https://codesandbox.io/s/crimson-water-0hxke?file=/src/App.js

    【讨论】:

    • 这很好用。原来我没有传递正确的链接,它被踢回本地主机而不是正确链接。感谢您的帮助!
    猜你喜欢
    • 2012-12-17
    • 1970-01-01
    • 2017-04-05
    • 2014-06-10
    • 2018-10-26
    • 2021-07-18
    • 1970-01-01
    • 2017-08-12
    相关资源
    最近更新 更多