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

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