• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

263
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 3 years ago · Santiago Trujillo
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 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error