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

Fix trailing slash with locale domain #52343

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/next/src/client/get-domain-locale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DomainLocale } from '../server/config'
import type { normalizeLocalePath as NormalizeFn } from './normalize-locale-path'
import type { detectDomainLocale as DetectFn } from './detect-domain-locale'
import { normalizePathTrailingSlash } from './normalize-trailing-slash'

const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''

Expand All @@ -21,7 +22,9 @@ export function getDomainLocale(
if (domain) {
const proto = `http${domain.http ? '' : 's'}://`
const finalLocale = target === domain.defaultLocale ? '' : `/${target}`
return `${proto}${domain.domain}${basePath}${finalLocale}${path}`
return `${proto}${domain.domain}${normalizePathTrailingSlash(
`${basePath}${finalLocale}${path}`
)}`
}
return false
} else {
Expand Down
22 changes: 22 additions & 0 deletions test/integration/i18n-support/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,28 @@ describe('i18n Support', () => {
return 'yes'
}, 'yes')
})

it('should have correct locale domain hrefs', async () => {
const res = await fetchViaHTTP(
curCtx.appPort,
'/do-BE/frank/',
undefined,
{
redirect: 'manual',
}
)
expect(res.status).toBe(200)

const html = await res.text()
const $ = cheerio.load(html)

expect($('#to-fallback-hello')[0].attribs.href).toBe(
'http://example.do/do-BE/gsp/fallback/hello/'
)
expect($('#to-no-fallback-first')[0].attribs.href).toBe(
'http://example.do/do-BE/gsp/no-fallback/first/'
)
})
}

it('should redirect correctly', async () => {
Expand Down