TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ludwiigdev/Heroes_App/llms.txt
Use this file to discover all available pages before exploring further.
Navbar component is the persistent top navigation bar rendered across every protected page of the Heroes App. It provides links to the Marvel, DC, and Search sections, displays the currently logged-in user’s name, and exposes a Logout button that clears authentication state and redirects to the login screen. Because Navbar sits inside HeroesRoutes — which is only reachable through PrivateRoute — it is never shown to unauthenticated users.
Where Navbar lives
Navbar is mounted once, at the top of HeroesRoutes, above the <Routes> definition:
HeroesRoutes component is itself protected by PrivateRoute inside AppRouter, so Navbar is guaranteed to render only for authenticated sessions.
Navigation links
The navbar contains four navigation targets:Heroes (Brand)
A plain
<Link> with the navbar-brand class pointing to /. Clicking it returns to the root route, which immediately redirects to /marvel.Marvel → /marvel
A
<NavLink> that highlights as active when the current path starts with /marvel. Renders the Marvel heroes listing.DC → /dc
A
<NavLink> that highlights as active when the current path starts with /dc. Renders the DC heroes listing.Search → /search
A
<NavLink> pointing to the search page. Becomes active when the URL is /search (with or without a ?q= query string).Active link styling
The three<NavLink> components use the className callback form to apply Bootstrap’s active class to whichever link matches the current URL:
isActive boolean automatically. When true, the rendered element receives both nav-item nav-link (Bootstrap) and active (Bootstrap active-state highlight) — no manual comparison or useLocation call is needed.
Right-side user section
The right side of the navbar reads the authenticated user object fromAuthContext and renders the name alongside a Logout button:
user?.name uses optional chaining so the span renders as empty if user is null or undefined, preventing a runtime error during any brief window where auth state is still initialising.
Logout flow
When the user clicks the Logout button,onLogout runs a two-step process:
Clear authentication state
logout() is provided by AuthContext. Inside AuthProvider it removes the "user" key from localStorage and dispatches a types.logout action to the authReducer, setting logged: false and user: null.Because the navigation uses
replace: true, the protected route the user was on is removed from the browser history stack. If they press Back they will land on whatever page was before they entered the app — typically an external page or a blank tab — rather than triggering a re-authentication loop.Props
Navbar accepts no props. All data it needs — user, logout — is read directly from AuthContext via useContext:
