4

I have an react application created using create-react-app.I have included a static html page in public.

I'm want to use that html in the same application using iframe.

The iframe with covid.html is not loading after the build.

-- Public

  • covid.html

enter image description here

After the build the iframe url looks like this

<iframe src="/covid.html"/>

which is considering the html file as 'www.mydomain.com/covid'

How do i use the html file in the Iframe in public folder?

I use BrowserRouter.

TIA

anud33p
  • 198
  • 4
  • 15
  • 1
    Does this answer your question? https://stackoverflow.com/questions/33913737/inserting-the-iframe-into-react-component – keikai Mar 18 '20 at 13:55
  • 1
    @keikai No. the answer has iframe with external urls. In my case the html is in the same project folder.I need to load the html file as src – anud33p Mar 18 '20 at 14:01
  • If the HTML is in your project file structure, why don't you simply `import` it as a normal react component? – keikai Mar 18 '20 at 14:02
  • @keikai the html internal has javascript functions and imports. If i import how do i display the html ? – anud33p Mar 18 '20 at 14:11
  • Show the full code thx. – keikai Mar 18 '20 at 14:12
  • 1
    @keikai the html ? – anud33p Mar 18 '20 at 14:14
  • I tried it in my app and it works for me. I made the `covid.html` in `public` directory. And I put `` in some react component. And it showed up. You might have some other problem. – karianpour Mar 18 '20 at 14:30
  • 1
    @karianpour did you build it and check ? It works in the while running the app.After the build it doesnt – anud33p Mar 18 '20 at 14:32
  • @anud33p , I tried also with build and in server. You might have some problem in the server or if you use `serviceworker` it might cause problem. – karianpour Mar 18 '20 at 14:40

0 Answers0