Proper way to redirect on getServerSideProps? Error: Cannot set headers after they are sent. #14664
Unanswered
arielpacciaroni
asked this question in
Help
Replies: 2 comments 3 replies
-
It looks like there was a Discussion on this here with no resolution at this time. Some have suggested this (although I have not tested it): ctx.res.setHeader('Location', '/my-page');
ctx.res.statusCode = 302;
ctx.res.end();
return { props: {} }; |
Beta Was this translation helpful? Give feedback.
1 reply
-
I'd be interested in the solution to this. I've also found this error in examples supplied by the next team, like the cool static tweet demo shared by @rauchg, code by @lfades, has this error every time it generates a new page. Would love to know what causes it! 👍 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm using NextJS along Express and everytime I visit a protected page (through client-side navigation), I get the error described above "Cannot set headers after they are sent." I tried using res.end() and still gives me the error above. This is the snippet I'm using
Any help would be appreciated! Thanks!
Beta Was this translation helpful? Give feedback.
All reactions