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

322
Vistas
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 Respuestas
Responde la pregunta

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