#How can i access a variable inside the --- in script?

4 messages · Page 1 of 1 (latest)

vocal kettle
#

I have an astro component, which i want to be able to redirect, using the slug route params to another page. The problem is, i am getting the slug inside the --- but i am calling the "click" eventListener inside the script tag, so its not getting the proper scope to get the variable.

---
import StandardGreenButton from "./StandardGreenButton.astro";

import servicesService from "../../services/services.service";

const slugify = Astro.params.slugify!;

const service = await servicesService.findBySlugify(slugify);
---

<script>
    const btnContinuar = document.getElementById('modalButtonConfirm')
    const btnCancelar = document.getElementById('cancelar')

    btnContinuar!.addEventListener('click', () => {
        // alert(window.location.hostname)
        if (window.location.hostname == 'localhost') {
            window.location.href = `http://localhost:3000/servicos/solicitar/${slugify}`
        }
    })
</script>

How can i achieve that?

clever mica
fossil slate
#

especially the section "Sharing State between Client and Server"