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

107
Visualizações
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 à 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