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
¿Cómo publicar una aplicación de reacción en cualquier directorio?

Tengo una aplicación de reacción que es posible que desee ejecutar desde diferentes directorios, posiblemente en varios hosts.

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

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

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

Me doy cuenta de que cuando hago clic en un enlace de inicio, la URL siempre muestra

https://myhost.com/home en lugar de https://myhost.com/relative/path/1/home

¿Es este el comportamiento esperado?

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

Estoy buscando una forma definitiva o una explicación sobre cómo hacer que la URL se vea como

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

en vez de

https://myhost.com/home

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

0

Me las arreglé para hacer esto.

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

Si coloca la salida de compilación en https://example.com/path/to/script baseUrl = '/path/to/script/';

  1. Rutas
 <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. Enlaces
 <Link to={`${baseUrl}home`}>Home</Link>
  1. .htaccess va al mismo directorio de 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 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!