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

bugfix/i18n Do not support the second locale in the pathname #31229

Merged
merged 7 commits into from Nov 11, 2021
4 changes: 2 additions & 2 deletions packages/next/server/router.ts
Expand Up @@ -318,9 +318,9 @@ export default class Router {
currentPathname = `${
getRequestMeta(req, '_nextHadBasePath') ? activeBasePath : ''
}${
activeBasePath && localePathResult.pathname === '/'
activeBasePath && currentPathnameNoBasePath === '/'
? ''
: localePathResult.pathname
: currentPathnameNoBasePath
}`
}

Expand Down
31 changes: 31 additions & 0 deletions test/integration/i18n-support/test/index.test.js
Expand Up @@ -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)
vordgi marked this conversation as resolved.
Show resolved Hide resolved
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}/` : ''}`
Expand Down