They are very similar in their description, but one does much more. The easiest way to see the difference is look at the source.
res.location
just sets the response header. It does not set a response status code or close the response, so you can write a response body if you want, and you have to call res.end()
on your own after.
res.redirect
on the other hand sets the status to 302, sets the header (using res.location
) and sends a nice response body saying that the user is being redirected, and renders a link if their browser doesn't automatically redirect them for some reason.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…