diff --git a/packages/next/server/router.ts b/packages/next/server/router.ts index fb0176c03274139..a9a9f6e4fb710d7 100644 --- a/packages/next/server/router.ts +++ b/packages/next/server/router.ts @@ -318,9 +318,9 @@ export default class Router { currentPathname = `${ getRequestMeta(req, '_nextHadBasePath') ? activeBasePath : '' }${ - activeBasePath && localePathResult.pathname === '/' + activeBasePath && currentPathnameNoBasePath === '/' ? '' - : localePathResult.pathname + : currentPathnameNoBasePath }` } diff --git a/test/integration/i18n-support/test/index.test.js b/test/integration/i18n-support/test/index.test.js index 7d8143b79a0900f..8212a6bb0827e46 100644 --- a/test/integration/i18n-support/test/index.test.js +++ b/test/integration/i18n-support/test/index.test.js @@ -412,6 +412,37 @@ describe('i18n Support', () => { } }) + it('should return 404 error for repeating locales', async () => { + const defaultLocale = 'en-US' + for (const locale of nonDomainLocales) { + for (const asPath of [ + '/gsp/fallback/always/', + '/post/comment/', + '/gssp/first/', + ]) { + const res = await fetchViaHTTP( + curCtx.appPort, + `/${locale}/${defaultLocale}${asPath}`, + undefined, + { + redirect: 'manual', + } + ) + expect(res.status).toBe(404) + const $ = cheerio.load(await res.text()) + const props = JSON.parse($('#props').text()) + console.log(props) + expect($('#not-found').text().length > 0).toBe(true) + expect(props).toEqual({ + is404: true, + locale, + locales, + defaultLocale, + }) + } + } + }) + it('should navigate between pages correctly', async () => { for (const locale of nonDomainLocales) { const localePath = `/${locale !== 'en-US' ? `${locale}/` : ''}`