Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
How to display a page that tells the user they are being redirected before redirecting them in Javascript

I am using JavaScript to get a device number and use that to create a url. From there the user is redirected to the website. I wanted to create a simple HTML page that displays a message for a few seconds letting the user know if they are being redirected, and if they are unable to redirect the user shows an error message.

I appreciate any help you advise you can give me.

import axios from 'axios'
import { useEffect } from 'react'
import './Welcome.css'


import config from './apiConfig' // eslint-disable-line no-unused-vars

let counter = document.querySelector('h1')
let count = 1

setInterval(() => {
  counter.innerText = count
  count++
}, 1000)

const Welcome = () => {
  const fetchLocationAndRedirect = () => {
    axios
      .get(
        'apiurl'
      )
      .then((res) => {
        console.log(res.data.location_id)
        var location_id = res.data.location_id
        //Create new url
        const myURL = new URL('https://' + location_id + '.com')

        if (typeof window !== 'undefined') {
          // browser code
          window.location.href = myURL // Redirect user to my website
        }
      })
      .catch((err) => console.log(err))
    //alert('foo')
  }

  useEffect(() => {
    fetchLocationAndRedirect()
  }, [])

  return <h1 style={{ float: 'center' }}>Now redirecting you to My Website</h1>

}

export default Welcome```
about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda