Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document redirect on getServerSideProps #18626

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/basic-features/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ If you export an `async` function called `getServerSideProps` from a page, Next.
export async function getServerSideProps(context) {
return {
props: {}, // will be passed to the page component as props
// or you can return a { redirect: {...} }, see below.
}
}
```
Expand All @@ -552,6 +553,11 @@ The `context` parameter is an object containing the following keys:
- `locales` contains all supported locales (if enabled).
- `defaultLocale` contains the configured default locale (if enabled).

You can either return `props` or a `redirect` object to redirect the user to another page. This object containing the following keys:

- `permanent`: If the redirection is permanent.
- `destination`: The destination of the redirection.

> **Note**: You can import modules in top-level scope for use in `getServerSideProps`.
> Imports used in `getServerSideProps` will not be bundled for the client-side.
>
Expand Down