Created
August 5, 2020 15:42
-
-
Save saqibameen/693572de8283b6946f363a52c811ad7a to your computer and use it in GitHub Desktop.
Server side and client side redirection in next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Router from 'next/router'; | |
const redirectLocation = '/error'; | |
// If server. | |
if (ctx.res) { | |
ctx.res.writeHead(303, { Location: redirectLocation }); | |
ctx.res.end(); | |
} else { | |
// If browser. | |
Router.push(redirectLocation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment