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!