I have some code here where I am trying to add routing to an index.html file (which I am running using liveServer on vscode). I do not understand how to properly "import" the required react components from the react-router-dom, which I have included in the file as a cdn through a script tag. I have been trying to compare my code to this site https://reacttraining.com/react-router/web/example/basic. Right now I am recieving the following error:
react-dom.development.js:24134 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Here is the code, any help would be greatly appreciated!!
<html>
<head>
<script
src="https://unpkg.com/react@16/umd/react.development.js"
crossorigin
></script>
<script
src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
crossorigin
></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script
crossorigin
src="https://cdnjs.cloudflare.com/ajax/libs/react-router-dom/5.1.2/react-router-dom.min.js"
></script>
<body>
<div id="root"></div>
<script type="text/babel">
const { BrowserRouter } = ReactRouterDOM;
const { Router } = ReactRouterDOM.BrowserRouter;
const { Route } = ReactRouterDOM.BrowserRouter;
const { Switch } = ReactRouterDOM.BrowserRouter;
class Home extends React.Component {
render() {
return <div>THIS IS HOME</div>;
}
}
class About extends React.Component {
render() {
return <div>THIS IS THE ABOUT PAGE</div>;
}
}
class Help extends React.Component {
render() {
return <div>THIS IS THE HELP PAGE</div>;
}
}
class App extends React.Component {
render() {
return (
<Router>
<Switch>
<Route exact={true} path="/">
<Home />
</Route>
<Route path="/about">
<About />
</Route>
<Route path="/help">
<Help />
</Route>
</Switch>
</Router>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
</script>
</body>
</head>
</html>