Creating the Navigation Bar
Explore how to create a responsive navigation bar in React using React-Bootstrap combined with react-router-dom. Understand how to set up routing to various components like movies list, movie details, reviews, and login/logout links that adapt based on user authentication state. This lesson prepares you to connect frontend navigation seamlessly to your backend server.
We'll cover the following...
In this lesson, we’ll add a navigation header bar that allows users to select different routes to access various components in the central part of the page. We’ll start by creating some simple components, and our router will load them, depending on the user’s URL route. The code files created previously have been provided below for reference:
import React from 'react'
import { Switch, Route, Link } from "react-router-dom"
import "bootstrap/dist/css/bootstrap.min.css"
function App() {
return (
<div className="App">
Hello World
</div>
);
}
export default App;We first create a components folder in the src folder.
Components
In the components folder, we’ll create four new component files:
-
The
movies-list.jscomponent lists movies. -
The
movie.jscomponent displays a single movie. -
The
add-review.jscomponent adds a review. -
The
login.jscomponent is the login component.
Let’s first use a ...