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

153
Views
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
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!