I am trying to render html using Route but browser is giving me following error:
Failed to compile.
./src/hello.html 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
<html> | Hello | </html>
I have already tried using babel but when I run npm start the terminal is telling me undo all the babel and webpack changes -
- Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
- Delete node_modules in your project folder.
- Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
- Run npm install or yarn, depending on the package manager you use. In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:
- If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.
- Check if /Users/shubhamnandanwar/Desktop/react/YourHourWebApp/node_modules/babel-loader is outside your project directory. For example, you might have accidentally installed something in your home folder.
- Try running npm ls babel-loader in your project folder. This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
This is my App.js file
import React, { Component } from "react";
import { BrowserRouter, Switch, Route } from "react-router-dom";
import Navbar from "./components/layout/Navbar";
import Dashboard from "./components/dashboard/Dashboard";
import UserStory from "./components/stories/UserStory";
import SignIn from "./components/auth/SignIn";
import SignUp from "./components/auth/SignUp";
import CreateStory from "./components/stories/CreateStory";
import { Redirect } from "react-router-dom";
class App extends Component {
reload = () => window.location.reload();
render() {
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/" component={TemplateHTMLComponent} />
<Route exact path="/stories" component={Dashboard} />
<Route path="/story/:id" component={UserStory} />
<Route path="/signin" component={SignIn} />
<Route path="/signup" component={SignUp} />
<Route path="/uploadStory" component={CreateStory} />
</Switch>
</div>
</BrowserRouter>
);
}
}
class TemplateHTMLComponent extends React.Component {
htmlFile = require("./hello.html");
render() {
return <div dangerouslySetInnerHTML={{ __html: this.htmlFile }} />;
}
}
export default App;
I am new in react and have spent hours trying to fix it. Can anyone please give me some direction