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

181
Views
Conditional routing using react-router-dom isn't working

So I have an issue where I am using conditional routing in an assignment and for some reason it's not returning the expected value so here is what the important part of the code looks like:

<Route
  path="/profile/:username?"
  element={<Profile />}
/>

However running like this keeps giving me an error that it couldn't find the page. When I checked out the useParams I found that instead of labeling the conditional username it would label it "*" and then have the full path in the output like this:

*:'/profile/dsamuelson'

yet when I take the question mark off then it labels the path correctly as username and gives me the page I want

username:'dsamuelson'

Does anyone have any idea why it's behaving like that. Literally every page I go to says that all you do is add the ? mark conditional lookback and it should work with or without the second field but it is just not working. Any help is greatly appreciated.

about 4 years ago · Juan Pablo Isaza
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!