I'm having troubles when trying to load a html file from my public folder in a React application created with create-react-app. Am I missing a config setting somewhere in webpack?
I currently have this folder structure:
And I want to show the test.html file inside an Iframe in my React component like this:
import React from 'react';
const Component = props => {
return (<iframe src="/test/index.html"title="Docuvieware" />);
};
export default Component;
But this is giving me a "Cannot GET /test/index.html" in the Iframe. Also when surfing directly to http://localhost:3000/test/index.html I get a white page that says 'Cannot GET /test/index.html'
I also tried to use "process.env.PUBLIC_URL" inside my component but this was undefined.
I have managed to fix this by using CopyWebpackPlugin. Just added the test folder in my src folder, and then added the following line to my webpack config:
new CopyWebpackPlugin([{ from: 'src/test', to: 'test' }]),
and then /test/index.html gave the correct path.