Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Last active September 7, 2020 07:30
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 hrdtbs/8d5c9e5cd11b80d9a9e2071edc521288 to your computer and use it in GitHub Desktop.
Save hrdtbs/8d5c9e5cd11b80d9a9e2071edc521288 to your computer and use it in GitHub Desktop.
Redirect to external page on Next.js
import { DocumentContext } from "next/document"
import React from "react"
const Page = () => {
return null
}
const Location = "hoge"
export const getServerSideProps = async (ctx: DocumentContext) => {
if (ctx.res) {
ctx.res.writeHead(301, { Location, "Content-Type": "hoge" })
ctx.res.end()
}
return { props: {} }
}
export default Page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment