Created
August 5, 2020 15:42
-
-
Save saqibameen/22b1aed7e2adcce8099c1c65164c2f9c 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