Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Pass String along a res.redirect(path) call in Express Node project

Pass String along a res.redirect(path) call in Express Node project

Problem

I am using res.redirect('/') after a save operation in an Express project

How can I Pass a certain string along with the redirect? I want to pass along some sort of notice to be displayed when the view is rendered. Many of my save/delete operations lead back to the main site or a certain subpage, so I would need a way to pass the string into the template where I can render it nicely.

I am using Coffee, Express and Jade for this project.

The function that catches that redirect is structured as such:

app.get '/', (req, res) ->
  // some stuff

Can i somehow add that string to the req object?

Problem courtesy of: arvidkahl

Solution

I suggest you use Express' req.flash, it was made for the purpose.

You can either iterate through your flashes in your template or use express-messages.

Solution courtesy of: Linus Gustav Larsson Thiel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Pass String along a res.redirect(path) call in Express Node project

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×