import React from 'react' ; import Router from 'next/router' ; import Head from 'next/head' ; export default ( redirectUrl , options ? ) => class extends React . Component { static async getInitialProps ( { res } ) { if ( res ?. writeHead ) { res . writeHead ( options ?. statusCode ?? 301 , { Location : redirectUrl } ) ; res . end ( ) ; } return { } ; } componentDidMount ( ) { if ( options ?. asUrl != null ) { Router . push ( redirectUrl , options . asUrl , { shallow : true } ) ; } else if ( redirectUrl [ 0 ] === '/' ) { Router . push ( redirectUrl ) ; } else { window . location . href = redirectUrl ; } } render ( ) { const href = options ?. asUrl ?? redirectUrl ; return ( < > < Head > { } < noscript > < meta httpEquiv = "refresh" content = { `0;url=${ href }` } / > < /noscript> { ( options ?. statusCode === undefined || options ?. statusCode === 301 ) && ( < link rel = "canonical" href = { href } / > ) } < /Head> { } { this . props . children ? ( this . props . children ) : ( < p > Redirecting to < a href = { href } > { href } < /a>&hellip; < /p>)} < />); } } ;