Redirect index to page

NextJS, Javascript

Redirect index to another page in NextJS applications.

javascript

import React from "react"; import Router from "next/router"; class Index extends React.Component { static async getInitialProps(ctx) { if (ctx && ctx.req) { ctx.res.writeHead(302, { Location: "/page" }); ctx.res.end(); } else { Router.push("/page"); } } } export default Index;