Skip to main content
Make question into actual question, tidy JS
Source Link
mikemaccana
  • 126.1k
  • 113
  • 441
  • 544

Redirecting How do I redirect in express,expressjs while passing some context?

I am using express to make a web app in node.js. This is a simplification of what I have:

var express  = require('express'); var jade  = require('jade'); var http  = require("http"); var app  = express(); var server = http.createServer(app); ///////////// // Routing // ///////////// app.get('/', function(req, res) {   // Prepare the context   res.render('home.jade', context); }); app.post('/category', function(req, res) {   // Process the data received in req.body   res.redirect('/'); }); 

My problem is the following:

If I find that the data sent in /category doesn't validate, I would like pass some additional context to the / page. How could I do this? Redirect doesn't seem to allow any kind of extra parameter.

Redirecting in express, passing some context

I am using express to make a web app in node.js. This is a simplification of what I have:

var express  = require('express'); var jade  = require('jade'); var http  = require("http"); var app  = express(); var server = http.createServer(app); ///////////// // Routing // ///////////// app.get('/', function(req, res) {   // Prepare the context   res.render('home.jade', context); }); app.post('/category', function(req, res) {   // Process the data received in req.body   res.redirect('/'); }); 

My problem is the following:

If I find that the data sent in /category doesn't validate, I would like pass some additional context to the / page. How could I do this? Redirect doesn't seem to allow any kind of extra parameter.

How do I redirect in expressjs while passing some context?

I am using express to make a web app in node.js. This is a simplification of what I have:

var express = require('express'); var jade = require('jade'); var http = require("http"); var app = express(); var server = http.createServer(app); app.get('/', function(req, res) { // Prepare the context res.render('home.jade', context); }); app.post('/category', function(req, res) { // Process the data received in req.body res.redirect('/'); }); 

My problem is the following:

If I find that the data sent in /category doesn't validate, I would like pass some additional context to the / page. How could I do this? Redirect doesn't seem to allow any kind of extra parameter.

Source Link
Enrique Moreno Tent
  • 25.6k
  • 35
  • 110
  • 195

Redirecting in express, passing some context

I am using express to make a web app in node.js. This is a simplification of what I have:

var express = require('express'); var jade = require('jade'); var http = require("http"); var app = express(); var server = http.createServer(app); ///////////// // Routing // ///////////// app.get('/', function(req, res) { // Prepare the context res.render('home.jade', context); }); app.post('/category', function(req, res) { // Process the data received in req.body res.redirect('/'); }); 

My problem is the following:

If I find that the data sent in /category doesn't validate, I would like pass some additional context to the / page. How could I do this? Redirect doesn't seem to allow any kind of extra parameter.