diff --git a/docs/api-reference/next.config.js/headers.md b/docs/api-reference/next.config.js/headers.md index e467d7363af114..435fadd6c94b15 100644 --- a/docs/api-reference/next.config.js/headers.md +++ b/docs/api-reference/next.config.js/headers.md @@ -26,6 +26,10 @@ Headers allow you to set custom HTTP headers for an incoming request path. To set custom HTTP headers you can use the `headers` key in `next.config.js`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async headers() { return [ @@ -62,6 +66,9 @@ Headers are checked before the filesystem which includes pages and `/public` fil If two headers match the same path and set the same header key, the last header key will override the first. Using the below headers, the path `/hello` will result in the header `x-hello` being `world` due to the last header value set being `world`. ```js +/** + * @type {import('next').NextConfig} + */ module.exports = { async headers() { return [ @@ -93,6 +100,9 @@ module.exports = { Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths): ```js +/** + * @type {import('next').NextConfig} + */ module.exports = { async headers() { return [ @@ -119,6 +129,9 @@ module.exports = { To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`: ```js +/** + * @type {import('next').NextConfig} + */ module.exports = { async headers() { return [ @@ -145,6 +158,9 @@ module.exports = { To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`: ```js +/** + * @type {import('next').NextConfig} + */ module.exports = { async headers() { return [ @@ -165,6 +181,10 @@ module.exports = { The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -190,6 +210,10 @@ To only apply a header when either header, cookie, or query values also match th - `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async headers() { return [ @@ -281,6 +305,10 @@ module.exports = { When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { basePath: '/docs', @@ -315,6 +343,10 @@ module.exports = { When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with headers each `source` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the header. If `locale: false` is used you must prefix the `source` with a locale for it to be matched correctly. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { i18n: { locales: ['en', 'fr', 'de'], diff --git a/docs/api-reference/next.config.js/introduction.md b/docs/api-reference/next.config.js/introduction.md index 32c72c02321c32..507d700f6fb343 100644 --- a/docs/api-reference/next.config.js/introduction.md +++ b/docs/api-reference/next.config.js/introduction.md @@ -11,6 +11,10 @@ For custom advanced behavior of Next.js, you can create a `next.config.js` in th Take a look at the following `next.config.js` example: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { /* config options here */ } @@ -20,9 +24,13 @@ You can also use a function: ```js module.exports = (phase, { defaultConfig }) => { - return { + /** + * @type {import('next').NextConfig} + */ + const config = { /* config options here */ } + return config } ``` diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index 7dd369881fee51..879378db62514c 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -28,6 +28,10 @@ Redirects are only available on the Node.js environment and do not affect client To use Redirects you can use the `redirects` key in `next.config.js`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -57,6 +61,10 @@ Redirects are checked before the filesystem which includes pages and `/public` f Path matches are allowed, for example `/old-blog/:slug` will match `/old-blog/hello-world` (no nested paths): ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -75,6 +83,10 @@ module.exports = { To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -93,6 +105,10 @@ module.exports = { To match a regex path you can wrap the regex in parentheses after a parameter, for example `/post/:slug(\\d{1,})` will match `/post/123` but not `/post/abc`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -109,6 +125,10 @@ module.exports = { The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -134,6 +154,9 @@ To only match a redirect when header, cookie, or query values also match the `ha - `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`. ```js +/** + * @type {import('next').NextConfig} + */ module.exports = { async redirects() { return [ @@ -208,6 +231,10 @@ module.exports = { When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { basePath: '/docs', @@ -235,6 +262,10 @@ module.exports = { When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { i18n: { locales: ['en', 'fr', 'de'], diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index f9ca6aaa971815..d131e1cee5c793 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -28,6 +28,10 @@ Rewrites act as a URL proxy and mask the destination path, making it appear the To use rewrites you can use the `rewrites` key in `next.config.js`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -53,6 +57,10 @@ Rewrites are applied to client-side routing, a `` will have Rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes by default. This behavior can be changed by instead returning an object instead of an array from the `rewrites` function since `v10.1` of Next.js: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return { @@ -92,6 +100,10 @@ module.exports = { When using parameters in a rewrite the parameters will be passed in the query by default when none of the parameters are used in the `destination`. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -107,6 +119,10 @@ module.exports = { If a parameter is used in the destination none of the parameters will be automatically passed in the query. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -122,6 +138,10 @@ module.exports = { You can still pass the parameters manually in the query if one is already used in the destination by specifying the query in the `destination`. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -142,6 +162,10 @@ module.exports = { Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths): ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -159,6 +183,10 @@ module.exports = { To match a wildcard path you can use `*` after a parameter, for example `/blog/:slug*` will match `/blog/a/b/c/d/hello-world`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -176,6 +204,10 @@ module.exports = { To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -191,6 +223,10 @@ module.exports = { The following characters `(`, `)`, `{`, `}`, `:`, `*`, `+`, `?` are used for regex path matching, so when used in the `source` as non-special values they must be escaped by adding `\\` before them: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async redirects() { return [ @@ -216,6 +252,10 @@ To only match a rewrite when header, cookie, or query values also match the `has - `value`: `String` or `undefined` - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific part of the value, e.g. if the value `first-(?.*)` is used for `first-second` then `second` will be usable in the destination with `:paramName`. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -294,6 +334,10 @@ module.exports = { Rewrites allow you to rewrite to an external url. This is especially useful for incrementally adopting Next.js. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return [ @@ -313,6 +357,10 @@ You can also have Next.js fall back to proxying to an existing website after che This way you don't have to change the rewrites configuration when migrating more pages to Next.js ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { async rewrites() { return { @@ -334,6 +382,10 @@ See additional information on incremental adoption [in the docs here](/docs/migr When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with rewrites each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the rewrite: ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { basePath: '/docs', @@ -360,6 +412,10 @@ module.exports = { When leveraging [`i18n` support](/docs/advanced-features/i18n-routing.md) with rewrites each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the rewrite. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly. ```js +/** + * @type {import('next').NextConfig} + */ + module.exports = { i18n: { locales: ['en', 'fr', 'de'],