DEV Community

Zobaer Ahmed Zihad
Zobaer Ahmed Zihad

Posted on

How to hide navbar and footer when 404 (Page not found) is showing ?

I have a react application. I want to hide navbar and footer when the page 404 (Page Not Found) is showing. But I can't do this.

I can hide footer for other pages based on pathnames. Like

import { useLocation } from "react-router-dom";

const location = useLocation();
if (location?.pathname === "/login" || "/sign-up") {
return null;
}

But this hiding method I can't use on 404 page Because there is no specific pathname. How can I hide ? Please give me some suggestions.

Top comments (0)