Last active
March 18, 2021 11:58
-
-
Save estebanmunchjones2019/ff3bd1cda341d58411bdee1a29bcd928 to your computer and use it in GitHub Desktop.
Next.js article for eincode.com -- React demo code
This file contains hidden or 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
import { Route, Switch} from 'react-router-dom'; | |
import './App.css'; | |
import Home from './Home'; | |
import About from './About'; | |
import Contact from './Contact'; | |
import Layout from './Layout'; | |
function App() { | |
return ( | |
<div className="App"> | |
<Layout> | |
<Switch> | |
{/* Routes are loaded inside these tags */} | |
<Route path="/contact" component={Contact}/> | |
<Route path="/about" component={About}/> | |
<Route path="/" component={Home}/> | |
</Switch> | |
</Layout> | |
</div> | |
); | |
} | |
export default App; |
This file contains hidden or 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
import React from 'react'; | |
function Home() { | |
return ( | |
<React.Fragment> | |
<h1>This is the Home page</h1> | |
<h2>This is the React demo</h2> | |
<h2>If you right click on this app, and choose 'View Page Source', you'll see that the HTML content doesn't include this paragraph.</h2> | |
</React.Fragment> | |
); | |
} | |
export default Home; |
This file contains hidden or 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
import { Link } from 'react-router-dom'; | |
import React from 'react'; | |
function Layout({children}) { | |
return ( | |
<React.Fragment> | |
<nav> | |
<ul> | |
<li> | |
<Link to="/">Home</Link> | |
</li> | |
<li> | |
<Link to="/about">About</Link> | |
</li> | |
<li> | |
<Link to="/contact">Contact</Link> | |
</li> | |
</ul> | |
</nav> | |
{children} | |
</React.Fragment> | |
) | |
} | |
export default Layout; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment