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

321
Visualizações
Switch case with pathname :id route React

I don't find the way ton fix my issue. I want a specific state if the route is '/blablabla/:id'. I know how to find the simple route as '/blabla'. With a if statement is ok but i need to use switch case. Thanks for your help

 useEffect(() => {
    switch (location.pathname) {
      case '/':
        setTitle('My Board');
        break;
      case '/offers':
        setTitle('My Offer');
        break;
      case '/invoice':
        setTitle('Invoices');
        break;
      case location.pathname.match(/\d+$/): -- The route is /invoice/:id --> the id is a number 
        setTitle('Invoice Number ***');
        break;
      default:
        setTitle('My Board');
    }
  }, [location]);
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Your regex just checks for numbers but not the characters before it. This checks for characters followed by a slash and numbers.

^([a-z]+\/[0-9]+)
over 4 years ago · Santiago Trujillo 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