-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Ensure index rewrite is matched with i18n correctly #20509
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
42735d5
Ensure index rewrite is matched with i18n correctly
ijjk 8d990a3
Merge remote-tracking branch 'upstream/canary' into i18n/index-rewrite
ijjk e0d562a
Update tests for other locales
ijjk 194c8d2
Merge branch 'canary' into i18n/index-rewrite
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/integration/i18n-support-index-rewrite/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
i18n: { | ||
// localeDetection: false, | ||
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en'], | ||
defaultLocale: 'en', | ||
domains: [ | ||
{ | ||
// used for testing, this should not be needed in most cases | ||
// as production domains should always use https | ||
http: true, | ||
domain: 'example.be', | ||
defaultLocale: 'nl-BE', | ||
locales: ['nl', 'nl-NL', 'nl-BE'], | ||
}, | ||
{ | ||
http: true, | ||
domain: 'example.fr', | ||
defaultLocale: 'fr', | ||
locales: ['fr-BE'], | ||
}, | ||
], | ||
}, | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: '/', | ||
destination: '/company/about-us', | ||
}, | ||
] | ||
}, | ||
} |
42 changes: 42 additions & 0 deletions
42
test/integration/i18n-support-index-rewrite/pages/[...slug].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react' | ||
|
||
const DynamicPage = (props) => ( | ||
<> | ||
<div>DynamicPage</div> | ||
<div id="props">{JSON.stringify(props)}</div> | ||
</> | ||
) | ||
|
||
export const getStaticPaths = async ({ locales }) => { | ||
const paths = [] | ||
|
||
for (const locale of locales) { | ||
paths.push({ | ||
params: { | ||
slug: ['hello'], | ||
}, | ||
locale, | ||
}) | ||
paths.push({ | ||
params: { | ||
slug: ['company', 'about-us'], | ||
}, | ||
locale, | ||
}) | ||
} | ||
|
||
return { | ||
fallback: false, | ||
paths, | ||
} | ||
} | ||
|
||
export const getStaticProps = async ({ params, locale }) => ({ | ||
props: { | ||
locale, | ||
params, | ||
hello: 'world', | ||
}, | ||
}) | ||
|
||
export default DynamicPage |
97 changes: 97 additions & 0 deletions
97
test/integration/i18n-support-index-rewrite/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import assert from 'assert' | ||
import cheerio from 'cheerio' | ||
import webdriver from 'next-webdriver' | ||
import { | ||
launchApp, | ||
killApp, | ||
findPort, | ||
nextBuild, | ||
nextStart, | ||
renderViaHTTP, | ||
check, | ||
} from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
const appDir = join(__dirname, '..') | ||
const locales = ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en'] | ||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should rewrite index route correctly', async () => { | ||
for (const locale of locales) { | ||
const html = await renderViaHTTP( | ||
appPort, | ||
`/${locale === 'en' ? '' : locale}` | ||
) | ||
const $ = cheerio.load(html) | ||
|
||
expect(JSON.parse($('#props').text())).toEqual({ | ||
params: { | ||
slug: ['company', 'about-us'], | ||
}, | ||
locale, | ||
hello: 'world', | ||
}) | ||
} | ||
}) | ||
|
||
it('should handle index rewrite on client correctly', async () => { | ||
for (const locale of locales) { | ||
const browser = await webdriver( | ||
appPort, | ||
`${locale === 'en' ? '' : `/${locale}`}/hello` | ||
) | ||
|
||
expect(JSON.parse(await browser.elementByCss('#props').text())).toEqual({ | ||
params: { | ||
slug: ['hello'], | ||
}, | ||
locale, | ||
hello: 'world', | ||
}) | ||
await browser.eval(`(function() { | ||
window.beforeNav = 1 | ||
window.next.router.push('/') | ||
})()`) | ||
|
||
await check(async () => { | ||
const html = await browser.eval('document.documentElement.innerHTML') | ||
const props = JSON.parse(cheerio.load(html)('#props').text()) | ||
assert.deepEqual(props, { | ||
params: { | ||
slug: ['company', 'about-us'], | ||
}, | ||
locale, | ||
hello: 'world', | ||
}) | ||
return 'success' | ||
}, 'success') | ||
} | ||
}) | ||
} | ||
|
||
describe('Custom routes i18n', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests(true) | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests() | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also match
/nl
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it matches all locales unless
locale: false
is specified, updated tests to reflect/test this