how to redirect in node.js


Question

I'm having some issues with redirecting between directories, the problem is I can manage to redirect to another file in different directory. My directory structure looks like this:

-views
  -add_user.jade

-routes
  -index.js

I try to redirect to add_ user.jade from index.js, how would you guys do it

res.redirect('???');

If index.js in the same directory as views, the code below works

-index.js
-views
  -add_user.jade

res.redirect('./add_users');
1
22
7/31/2012 12:05:14 PM

Accepted Answer

You want to redirect to the URL (not the view name) that you want the user to go to.

For example, if the route "/user/add" renders the "add_user.jade" view then you want to use

 res.redirect("/user/add");
49
7/17/2014 5:15:30 PM

Yes, you can redirect on Url with the help of

return res.redirect('/server/Thank'); 

Thank is a view file with Thank.jade extension.

and route is /server/thank


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon