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

133
Views
redirect to same component under different conditions?

I am trying to redirect to same component but under diffract conditions and i am using windows.location.pathname as a way to know when the user is hitting the second endpoint my question is there a way to know the current location ? I tried to use context but it wont work because I don't want the context provider to give state to the main page that I am redirecting from also could my approach be considered bad ?

  <Route path='/creator' exact component={maincomponent} />
  <Route path='/viewer' exact component={maincomponent} />

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to learn the current path, you can use useLocation from react-router-dom.

For example:

import { useLocation } from 'react-router-dom'

function PathView() {
  const location = useLocation();
  const currentPath = location.pathname

  return <span>{currentPath}</span>
}

But if you want to use Routes with if condition, you can simply use {}.

For example:

{"YOUR_VARIABLE" === "YOUR_VARIABLE" ? (
  <Route path='/creator' exact component={maincomponent} />
) : (
  <Route path='/viewer' exact component={maincomponent} />
)
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!