React Pages With Router
React Pages With Router
1. Project Structure
src/
├── App.js
├── components/
│ ├── Navbar.js
│ ├── Header.js
│ ├── Footer.js
│ └── MainContent.js
├── pages/
│ ├── Home.js
│ ├── About.js
│ └── Contact.js
└── index.js
2. App.js
function App() {
return (
<Router>
<Navbar />
<Routes>
</Routes>
</Router>
);
3. Navbar.js
return (
<nav style={styles.nav}>
<ul style={styles.navLinks}>
</ul>
</nav>
);
};
const styles = {
nav: { display: 'flex', justifyContent: 'space-between', padding: '10px 20px', backgroundColor: '#333',
color: '#fff' },
logo: { margin: 0 },
};
4. Header.js
<header style={styles.header}>
<h1>{title}</h1>
</header>
);
const styles = {
};
<footer style={styles.footer}>
</footer>
);
const styles = {
footer: { padding: '10px', backgroundColor: '#333', color: '#fff', textAlign: 'center', marginTop: '20px' },
};
6. MainContent.js
<main style={styles.main}>
<p>{content}</p>
</main>
);
const styles = {
main: { padding: '20px' },
};
7. Home.js
<div>
<MainContent content="This is the home page of our website. We hope you enjoy your stay!" />
<Footer />
</div>
);
8. About.js
<div>
<Footer />
</div>
);
9. Contact.js
<div>
<MainContent content="Feel free to reach out to us through the provided contact information." />
<Footer />
</div>
);