Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Disable header and footer on custom url with :id

I'm trying to disable my Header and Footer components on my Product page. Here is my code:

const HeaderRoute = useCallback(
    () =>
      !["/create", "/sign-up", "/sign-in", "/product"].includes(
        window.location.pathname
      ) && <Header />,
    []
  );

However, my Product component url contains custom :id or path="/product/:id" :

<Route exact path="/product/:id" component={Product} />

The header doesn't render on the other urls, but it does on the /product:id url for some reason. Any ideas why?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solution

The method includes searches for exact matches, so that ['/product'].includes('product') is false.

If you want to see if a string matches inside another you can use match.

Your condition will be like:

const HeaderRoute = useCallback(
    () =>
      !["/create", "/sign-up", "/sign-in", "/product"].some(path => 
         window.location.pathname.match(path)
      ) && <Header />,
    []
  );

Working example

function showHeader(pathname) {
  return !["/create", "/sign-up", "/sign-in", "/product"].some(path => pathname.match(path));
}

console.log(showHeader("/product:id")); // false
console.log(showHeader("/create")); //false
console.log(showHeader("/create/new:id")); //false
console.log(showHeader("/anotherPage")); //true

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda