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

251
Visualizações
How to publish a react app in any directory?

I have a react app which I may want to run from different directories possibly on multiple hosts.

https://myhost.com/relative/path/1/index.html

https://myhost.com/relative/path/2/index.html

https://myhost2.com/relative/path/1/index.html

I notice when I click on a home link URL always shows

https://myhost.com/home instead of https://myhost.com/relative/path/1/home

Is this expected behavior?

<Link to={`${this.settings.getClientBaseUrl()}home`}>Home</Link>
<Route exact path={`${this.settings.getClientBaseUrl()}`} element={<HomePage parent={this.parent} />} />

I am looking for a definitive way or explanation on how to have the URL look like

https://myhost.com/relative/path/1/home

instead of

https://myhost.com/home

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I managed to do this.

  1. Base Url
let baseUrl = window.location.pathname;
baseUrl = \`${baseUrl.split('/').slice(0, -1).join('/')}/\`; // get dir of filepath

If you put the output of build in https://example.com/path/to/script baseUrl = '/path/to/script/';

  1. Routes
<Route exact path={`${baseUrl}`} element={<HomePage props={props} />} />
<Route exact path={`${baseUrl}index.html`} element={<HomePage props={props} />} />
<Route exact path={`${baseUrl}home`} element={<HomePage props={props} />} />
  1. Links
<Link to={`${baseUrl}home`}>Home</Link>
  1. .htaccess goes into the same directory of the react index.html
# begin redirect to index.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.html [L]
# end redirect to index.html
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