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

259
Views
React Router Dom Relative Path

I have an application published in a domain similar to this "www.domain.com/app/client/store"

When I developed it at the beginning, it was not contemplated that the domain be that way but something like "www.domain.com" the issue is that it is causing problems with the Router

when you access the initial route "www.domain.com/app/client/store" it does not find the path that is the login and jumps to management

I need that regardless of the url always find the initial path which "/"

My router currently looks like this

const Routes = () => {
  return (
    <Router>
      <Switch>
        <Route exact path="/" component={Login} />
        <Route exact path="/main" component={Main} />
        <Route exact path="/main/:id" component={Main} />
        <Route exact="/management" component={Management} />
      </Switch>
    </Router>
  );
};

The domain will be relative so it is not a good idea to put the absolute URL in the path

How can I make the route relative and not affect the initial page of the application?

The routes would be more or less like this

"www.domain.com/app/client1/store5" "www.domain.com/app/client5/store1" "www.domain.com/app/client2/store3"

Thanks in advance for your help and feedback

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

0

In order to properly route, your path requires the public URL appended to every route.

const baseURL = process.env.PUBLIC_URL;

const Routes = () => {
  return (
    <Router>
      <Switch>
        <Route exact path="${baseURL}/" component={Login} />
        <Route exact path="${baseURL}/main" component={Main} />
        <Route exact path="${baseURL}/main/:id" component={Main} />
        <Route exact="${baseURL}/management" component={Management} />
      </Switch>
    </Router>
  );
};


Something like that should work. There are also packages out there you could use in order to make life easier that would automatically append this, But this is a pretty simple approach.

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!