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

112
Vistas
Routing using fetch requests and Express Handlebars

Can somebody help me figure it out why it's not working? I making routing an impromptu web marketplace for my portfolio and faced this problem. I'm using fetch request to send get to the server this way:

$('#about').click(function (){
        fetch('/about').then((e)=>{
            console.log(e.body)
        })
    })
    $('.logo').click(function (){
        fetch('/').then((e)=>{
            console.log(e.body)
        })
    })

and i need to send the hbs partial to the client-end. That's the way i doing it:

app.get('', (req,res)=>{
console.log('Server got index request')
res.render('index', {
    title: 'Marketplace',
    name: 'name',
    about: false,
    index: true,
    clientScript: clientScript,
    stylefile: styleFile,
    studiopage:'link'
})


app.get('/about', (req,res)=>{
    console.log('Server got about request')
    res.render('index', {
        title: 'Marketplace',
        about: true,
        index: false,
        name: 'name',
        clientScript: clientScript,
        stylefile: styleFile,
        studiopage:'link'
    })
})

This is the index.hbs structure:

<main>
    {{#if about}}
        {{>about}}
    {{/if}}
    {{#if index}}
        {{>productRows}}
    {{/if}}
</main>

So the problem is that the server receives the request, sends it back along with the value corresponding to the desired route (for example about: true), but the index on the client-end not being updated.

Thank you very much for your help in advance!

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