2022-11-19 14:21:26 +00:00
|
|
|
// next imports
|
2022-11-25 11:00:41 +00:00
|
|
|
import type { NextPageContext } from "next";
|
2022-11-19 14:21:26 +00:00
|
|
|
import Router from "next/router";
|
|
|
|
|
2022-11-25 11:00:41 +00:00
|
|
|
const redirect = (context: NextPageContext, target: any) => {
|
2022-11-19 14:21:26 +00:00
|
|
|
if (context.res) {
|
|
|
|
// server
|
|
|
|
// 303: "See other"
|
|
|
|
context.res.writeHead(301, { Location: target });
|
|
|
|
context.res.end();
|
|
|
|
} else {
|
|
|
|
// In the browser, we just pretend like this never even happened ;)
|
|
|
|
Router.push(target);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default redirect;
|