Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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]+)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!