Context: I want to load an html file into a react application and display part of it in a help window. The html file can be updated anytime from some content generator, so translating it into jsx is not an option.
Right now I'm trying to load any file (json included) using axios and getting 404 response. I put the call in componentWillMount, componentDidMount, whatever. I've peppered the project with toto.html and toto.json files. I created the app using create-react-app
import React, {Component} from 'react';
import axios from 'axios';
class Toto extends Component {
componentWillMount () {
console.log("inside componentWillMount")
axios
.get('./toto.json')
.then(response =>
{ console.log("json response=",response); })
.catch( error => {
console.log("json error=",error);} );
axios
.get('./toto.html')
.then(response =>
{ console.log("html response=",response); })
.catch( error =>
{ console.log("html error=",error);} );
console.log("inside componentWillMount 2")
};
render() {
return (
<div>
<h2>Toto TIti Tata</h2>
<object type="text/html" data="./toto.html" ></object>
</div>
)
}};
export default Toto;
Response:
inside componentDidMount Toto.js:11
inside componentDidMount 2 Toto.js:30
html error= Error: "Request failed with status code 404"
createErrorhttp://localhost:3000/static/js/bundle.js:1555:15settlehttp://localhost:3000/static/js/bundle.js:1721:12handleLoadhttp://localhost:3000/static/js/bundle.js:1081:7 Toto.js:27
json error = Error: "Request failed with status code 404"