React Router
// NOTE: This example needs the "react-router-dom" package, which is not
// installed in this sandbox by default. Add it as a dependency to run this
// example as-is.
import { BrowserRouter, Routes, Route } from "react-router-dom";
// Home/About/Contact would normally live in their own files and be
// imported (import Home from "./Home"; etc.). They're defined inline here
// since this sandbox only runs a single file.
function Home() {
return <h2>Home</h2>;
}
function About() {
return <h2>About</h2>;
}
function Contact() {
return <h2>Contact</h2>;
}
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
<Route path="*" element={<h1>404: Page Not Found</h1>} />
</Routes>
</BrowserRouter>
);
}
export default App;