Error: Can’t set headers after they are sent

Front end developers must read! Starting from scratch, teach you to build a low code website platform in stages>>>

When using res. redirect(), there are always errors as shown in the title

The reason is that after redirect(), the node does not stop executing, but continues to execute the following code. The page has jumped and the request response has ended. If the subsequent code still processes req, res will have a problem

So when you use res. redirect(), you must add return, that is, return res. redirect (‘/ dir’)

Of course, if the statement is the last line, return is not required

Similar Posts: