Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to hide Footer componenet in some page

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    <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 🙂

>Solution :

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 };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading