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

176
Views
Cómo obtener la URL principal del proyecto en reactjs

Estoy trabajando con reactjs y quiero obtener la ruta completa/nombre de host/baseurl de mi proyecto (archivo de componente interno). ¿Cómo puedo hacer esto? Intenté con el siguiente código, pero no funciona, me da el siguiente error

 "Unexpected token `{`. Expected * for generator"

Intenté con el siguiente código

 import absoluteUrl from 'next-absolute-url'; class Header extends Component { const { origin } = absoluteUrl(req) const apiURL = ${origin} render() { ...//my code } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Qué tal usar el objeto de ventana?

Nota: cuando use la ventana, envuélvala dentro de la siguiente condición si, de lo contrario, se producirá un error cuando esté usando SSR.

 import '../styles/globals.css'; function MyApp({ Component, pageProps }) { let fullPath = ''; if (typeof window !== undefined) { fullPath = window.location.hostname; } console.log(fullPath); return <Component {...pageProps} className={fullPath === 'insert your path here' ? 'insert class to apply if true' : 'insert class to apply if false'}/>; } export default MyApp;

apilar

about 4 years ago · Juan Pablo Isaza Report

0

En primer lugar, recuerde que su código se ejecuta en el cliente y el servidor, por lo que cualquier acceso a la ventana debe incluirse en una verificación.

 if (typeof window !== 'undefined') { var path = location.protocol + '//' + location.host + '/someting'; // (or whatever) } else { // work out what you want to do server-side... }
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!