Now that my photo sharing app is growing, I need to add more pages and implement routing.
First, in the command line, npm install react-router-dom
. Then, in App.js
importBrowserRouter
, Routes
, Link
and Route
from react-router-dom
.
BrowserRouter
Adding BrowserRouter
creates a base router, anything outside of it will be rendered on every page. If you have a NavBar, a header or a footer, leave them outside of the BrowserRouter
scope.
Routes
Next, adding Routes
in the BrowserRouter
scope you can add as manyRoute
elements as you would like.
Links
Finally add a link for users to be able to click. In the end, it should look like this: