From e6c1aa6483ecc98aaaa42cce50ee94ef274aa883 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 4 Dec 2020 07:32:50 -0600 Subject: [PATCH] Add locale: false custom route prefix note (#19765) This makes sure to note how custom-routes need to be prefixed when `locale: false` is used for routes to be matched correctly. Closes: https://github.com/vercel/next.js/issues/19703 --- docs/api-reference/next.config.js/headers.md | 13 ++++++++++++- docs/api-reference/next.config.js/redirects.md | 9 ++++++++- docs/api-reference/next.config.js/rewrites.md | 8 +++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/api-reference/next.config.js/headers.md b/docs/api-reference/next.config.js/headers.md index b3aaf30bcd..85b513c163 100644 --- a/docs/api-reference/next.config.js/headers.md +++ b/docs/api-reference/next.config.js/headers.md @@ -178,7 +178,7 @@ module.exports = { ### Headers with i18n support -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: +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 module.exports = { @@ -209,6 +209,17 @@ module.exports = { }, ], }, + { + // this matches '/' since `en` is the defaultLocale + source: '/en', + locale: false, + headers: [ + { + key: 'x-hello', + value: 'world', + }, + ], + }, ] }, } diff --git a/docs/api-reference/next.config.js/redirects.md b/docs/api-reference/next.config.js/redirects.md index 6f3ccf1c07..4ee91c3fc4 100644 --- a/docs/api-reference/next.config.js/redirects.md +++ b/docs/api-reference/next.config.js/redirects.md @@ -122,7 +122,7 @@ module.exports = { ### Redirects with i18n support -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: +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 module.exports = { @@ -145,6 +145,13 @@ module.exports = { locale: false, permanent: false, }, + { + // this matches '/' since `en` is the defaultLocale + source: '/en', + destination: '/en/another', + locale: false, + permanent: false, + }, ] }, } diff --git a/docs/api-reference/next.config.js/rewrites.md b/docs/api-reference/next.config.js/rewrites.md index 0ae1af38dc..28c0401789 100644 --- a/docs/api-reference/next.config.js/rewrites.md +++ b/docs/api-reference/next.config.js/rewrites.md @@ -166,7 +166,7 @@ module.exports = { ### Rewrites with i18n support -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: +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 module.exports = { @@ -187,6 +187,12 @@ module.exports = { destination: '/nl/another', locale: false, }, + { + // this matches '/' since `en` is the defaultLocale + source: '/en', + destination: '/en/another', + locale: false, + }, ] }, }