Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda