- Published on
How to do Redirection in Next.js getServerSideProps
- Authors
- Name
- Ashik Nesin
- @AshikNesin
There could be cases in which you might want to do temporary or permanent redirection like for example redirecting broken link or redirecting to auth page (if the user is not logged in).
For such cases perform redirection easily by returning redirect object with permanent and destination (where you want to redirect)
export default function App() {
// Your UI Here or just return it as null
return null;
}
export async function getServerSideProps(context) {
return {
redirect: {
permanent: false,
destination: "https://example.com",
},
};
}
Related
Happy simple redirections!