Skip to content

Instantly share code, notes, and snippets.

@saqibameen
Created August 5, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqibameen/693572de8283b6946f363a52c811ad7a to your computer and use it in GitHub Desktop.
Save saqibameen/693572de8283b6946f363a52c811ad7a to your computer and use it in GitHub Desktop.
Server side and client side redirection in next.js
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