Let's say i have an index route:
router.get('/', (req, res) => {
res.render('index', {
title: 'Home',
etc: etc...
});
});
In this route i have a post from a form or something:
router.post('/', async(req, res) => {
const something = req.something;
await something.save(); //Save to database, it's just an example quick code
res.render('index', {
title: 'Home',
success: true,
etc: etc...
});
});
As you see i re-render the page with the success: true locals. It is used in the templating for displaying a message. However if the user refreshes the re-rendered page he will see the message again.
I'm using handlebars at clientside if that matters, like
<body>
...
{{#if success}}
<script>alert('Your data saved!')</script>
{{/if}}
</body>
Is it possible to send that "success" without a re-render, and without seeing it multiple times if the user refreshes the page? If i can avoid the re-rendering that would be good enough.