Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
How to hide Footer component for some pages in react

i would like to hide footer component in some page

app.js

<div className="App">
  <Header setShowMenu={setShowMenu} />
  {showMenu ? <Menu navigateTo={navigateTo} setShowMenu={setShowMenu} /> : null}
  <Main navigateTo={navigateTo} />
  <Footer navigateTo={navigateTo} />
</div>

main.jsx

<div>
    <Routes>
        <Route path="/" element={<HomePage navigateTo={navigateTo} />}  />
        <Route path="/precard" element={<PreCard />}  />
        <Route path="/order" element={<Order />}  />
        <Route path="/contact" element={<Contact />}  />
        <Route path="/thankspage" element={<ThanksPage navigateTo={navigateTo}/>}  />
        <Route path="/*" element={<HomePage />} />
    </Routes>
</div>

Note: The Router in index.js

So I want to hide the footer in ./order Page

I hope you guys have solution for me :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use useLocation() hook to check the route path in the <Footer /> component and based on the pathname you can render the <Footer /> component.

Example :

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

const Footer = () => {
  const { pathname } = useLocation();
  console.log(pathname);
  // you can check a more conditions here
  if (pathname === "/thanks") return null;

  return <div className="footer">Footer</div>;
};
export { Footer };

App.js

import { Route, Switch, BrowserRouter } from "react-router-dom";
import "./styles.css";
import { Home } from "./pages/Home";
import { Catalog } from "./pages/Catalog";
import { Thanks } from "./pages/Thanks";
import { Header } from "./components/Header";
import { Footer } from "./components/Footer";
import { Page404 } from "./pages/Page404";

const App = () => {

  return (
    <>
      <BrowserRouter>
        <Header />
        <Switch>
          <Route path={"/"} exact>
            <Home />
          </Route>
          <Route path={"/catalog"} exact>
            <Catalog />
          </Route>
          <Route path={"/thanks"} exact>
            <Thanks />
          </Route>
          <Route path={"*"}>
            <Page404 />
          </Route>
          {/* <Redirect to={'/'} /> */}
        </Switch>
        <Footer />
      </BrowserRouter>
    </>
  );
};

export { App };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!