Created
August 20, 2020 22:06
-
-
Save abelsan/afd306c93c0dd70e84c8e27e32691c9c to your computer and use it in GitHub Desktop.
Cleaner standalone react router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Template</title> | |
<!-- don't use this in production: --> | |
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | |
</head> | |
<body> | |
<h1>Template</h1> | |
<!-- we will put our teact component inside this div --> | |
<div id="root"></div> | |
<!-- load react --> | |
<script src="https://unpkg.com/react/umd/react.development.js" crossorigin></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js" crossorigin></script> | |
<script src="https://unpkg.com/react-router/umd/react-router.min.js" crossorigin></script> | |
<script src="https://unpkg.com/react-router-dom/umd/react-router-dom.min.js" crossorigin></script> | |
<!-- load our react component. --> | |
<script src="CleanerRouter.js" defer type="text/babel"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Router = ReactRouterDOM.BrowserRouter; | |
const Route = ReactRouterDOM.Route; | |
const Link = ReactRouterDOM.Link; | |
const Prompt = ReactRouterDOM.Prompt; | |
const Switch = ReactRouterDOM.Switch; | |
const Redirect = ReactRouterDOM.Redirect; | |
const HashRouter = ReactRouterDOM.HashRouter; | |
function About(){ | |
return (<h3>About</h3>); | |
} | |
function Home(){ | |
return (<h3>Home</h3>); | |
} | |
function Spa() { | |
return ( | |
<HashRouter> | |
<div> | |
<Link to="/">Home</Link><span>, </span> | |
<Link to="/about/">About</Link> | |
<Route path="/" exact component={Home} /> | |
<Route path="/about/" component={About} /> | |
</div> | |
</HashRouter> | |
); | |
} | |
ReactDOM.render( | |
<Spa/>, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
append history for react-router
<script src="https://unpkg.com/history/umd/history.development.js" crossorigin></script>