reactrouter
reactrouter
Slim toumi
Slim toumi
React js tips
Slim toumi
Slim toumi
React js tips
Explanation
BrowserRouter: Wraps the entire app to enable routing.
Routes: Holds all individual <Route> elements.
Route: Defines a page. The path is the URL, and element is the
component to display.
Slim toumi
Slim toumi
React js tips
Home.js :
About.js :
Slim toumi
Slim toumi
React js tips
Navbar.js :
Explanation
Link: Creates clickable navigation to different pages in the app.
Slim toumi
Slim toumi
React js tips
Navbar.js :
Explanation
Navbar Outside of Routes: By placing <Navbar /> outside of
<Routes>, the navigation bar is always displayed, no matter
which page or route the user is on. This makes the navbar
accessible on all pages.
Slim toumi
Slim toumi
React js tips
NotFound.js :
App.js :
Slim toumi
Slim toumi
React js tips
About.js :
Explanation
The useNavigate hook from react-router-dom allows you to
programmatically navigate between routes in your application.
In this example, it creates a button that navigates the user back
to the home page ('/') when clicked, allowing for smooth
transitions without traditional link elements.
Slim toumi
Slim toumi
React js tips
Slim toumi
Slim toumi
React js tips
Slim toumi
Slim toumi