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

323
Visualizações
Javascript location.href not working on amplify server

I have the following code working fine on my local

    searchForm.addEventListener('submit', (e) => {
      e.preventDefault()

      new google.maps.Geocoder().geocode( { 'address': input.value }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          console.log(results[0].geometry.location.lat(), results[0].geometry.location.lng())

          let url = new URL(`http://${window.location.host}/page--node--1.html?location=${results[0].formatted_address}`)
          location.href = url

          return false
        } 
        console.log('Geocode was not successful for the following reason: ' + status)
        input.classList.add('error')
        errorMessage.style.display = 'block'
        
      })
    })

There seems to be a problem on my staging server with amplify when this code runs it redirects to https://main.23103jf.amplifyapp.com/page--node--1/ when it should be something like this https://main.23103jf.amplifyapp.com/page--node--1.html?location=and query params here

and this loads the root directory of the site with none of the assets loading.

EDIT

I have gotten more luck using the following code

    searchForm.addEventListener('submit', (e) => {
      e.preventDefault()

      new google.maps.Geocoder().geocode( { 'address': input.value }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          console.log(results[0].geometry.location.lat(), results[0].geometry.location.lng())

          if (window.location.host.includes('amplifyapp')) {
            console.log('on amplify')
            setTimeout(() => {
              location.href = '/page--node--1.html'
            }, 1000)
          } else {
            let url = new URL(`http://${window.location.host}/page--node--1.html?location=${results[0].formatted_address}`)
            location.href = url
          }
        } 
        console.log('Geocode was not successful for the following reason: ' + status)
        input.classList.add('error')
        errorMessage.style.display = 'block'
      })

      return false
    })

i'm going to the correct page only when I add this query parameter ?location=${results[0].formatted_address}` it breaks again

any help is appreciated thanks

about 4 years ago · Juan Pablo Isaza
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