Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda