本文介绍了如何在反应中制作外部超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始反应并在组件中包含此链接:

I'm new to react and have this link in a component:

<a href="https://example.com/faq.html"> FAQ </a>

我想在响应之外处理 faq.html.

I want to server faq.html outside react.

问题是反应将链接视为内部链接并给出404.

The problem is that react treats the link as internal and gives 404.

我看到了一个类似的问题,建议使用 <Route ...,但后来我不知道如何将超链接转换为路由.

I have seen a similar question which suggest to use <Route ..., but then I don't know how to convert the hyperlink to a Route.

我也知道我可以将 target="_blank" 添加到标签中,但这不是我理想的解决方案.

Also I know that I can add target="_blank" to the tag, but that's not my ideal solution.

非常感谢您帮助解决这个问题.

So appreciate your help to solve this.

推荐答案

你想多了.您可以像使用 HTML 一样执行此操作.这就是 JSX 的重点.你不需要路由.在此上下文中,外部链接不是路由.也许您弄错了一些周围的代码,但从您的示例中看不到这一点.

You're overthinking this. You can do it just like you would with HTML. That's the point of JSX. You don't need Route. An external link isn't a route in this context. Maybe you got some surrounding code wrong but can't see that from your example.

如果您想包含其他组件,您需要将它们包装在所有一个组件中.例如,使用Div"或片段<></>.否则,您可以像使用 HTML 一样执行此操作.

If you want to include other components you need to wrap them in all one component. For example with 'Div' or a fragment <></>. Otherwise, you can do it just as you would with HTML.

*rel="noreferrer";出于安全考虑,建议使用.

*rel="noreferrer" recommended for security.

  <a href="https://example.com/faq.html" rel="noreferrer">
    FAQ
  </a>

这篇关于如何在反应中制作外部超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:11