Skip to content

Instantly share code, notes, and snippets.

@sarthakxv
Created August 3, 2021 11:35
Show Gist options
  • Select an option

  • Save sarthakxv/9464104e222690c2385914e8b8cd3c9c to your computer and use it in GitHub Desktop.

Select an option

Save sarthakxv/9464104e222690c2385914e8b8cd3c9c to your computer and use it in GitHub Desktop.
Linking pages in React using react-router-dom package
// importing Router and Route
import { BrowserRouter as Router, Route } from "react-router-dom";
// Pages we need to link
import HomePage from "./Pages/HomePage/index";
import AlbumPage from "./Pages/AlbumPage/index";
import GalleryPage from "./Pages/GalleryPage/index";
// root App component
const App = () => {
return (
<div>
<Router>
<Route exact path="/" component={HomePage} />
<Route path="/albums" component={AlbumPage} />
<Route path="/albums/gallery" component={GalleryPage} />
</Router>
</div>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment