6

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

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

I want to server faq.html outside react.

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

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.

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.

narad
  • 359
  • 2
  • 4
  • 11

2 Answers2

3

First you need to create a new Route let faq

<Route path='/faq' component={() => window.location = 'https://example.com/faq.html'}/>

Then change your anchor tag href attribute to

<a href="/faq"> FAQ </a>

Hope it works !!

Midhun G S
  • 736
  • 7
  • 19
3

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.

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" recommended for security.

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