JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

res.redirect -- why do you need "/card" at the front?

the router.get assumes the /card, so we only need /, so why does the res.redirect need this as well?

2 Answers

Tom Geraghty
Tom Geraghty
24,147 Points

From the documentation:

Redirects can be relative to the root of the host name. For example, if the application is on http://example.com/admin/post/new, the following would redirect to the URL http://example.com/admin:

res.redirect('/admin');

Redirects can be relative to the current URL. For example, from http://example.com/blog/admin/ (notice the trailing slash), the following would redirect to the URL http://example.com/blog/admin/post/new.

res.redirect('post/new');

Redirecting to post/new from http://example.com/blog/admin (no trailing slash), will redirect to http://example.com/blog/post/new.

Ikuyasu Usui
Ikuyasu Usui
45,262 Points

You can also do in card.pug:

a(href=`./`) Next question

or './' or "./". The dot following flash indicates the current relative location. whereas '/' or "/" indicates the root.