-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure i18n with basePath works properly (#19083)
- Loading branch information
Showing
30 changed files
with
3,233 additions
and
1,950 deletions.
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
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
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
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,91 @@ | ||
module.exports = { | ||
// target: 'experimental-serverless-trace', | ||
// basePath: '/docs', | ||
i18n: { | ||
// localeDetection: false, | ||
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'], | ||
defaultLocale: 'en-US', | ||
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 redirects() { | ||
return [ | ||
{ | ||
source: '/en-US/redirect', | ||
destination: '/somewhere-else', | ||
permanent: false, | ||
}, | ||
{ | ||
source: '/nl/redirect', | ||
destination: '/somewhere-else', | ||
permanent: false, | ||
}, | ||
{ | ||
source: '/redirect', | ||
destination: '/somewhere-else', | ||
permanent: false, | ||
}, | ||
] | ||
}, | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: '/en-US/rewrite', | ||
destination: '/another', | ||
}, | ||
{ | ||
source: '/nl/rewrite', | ||
destination: '/another', | ||
}, | ||
{ | ||
source: '/rewrite', | ||
destination: '/another', | ||
}, | ||
] | ||
}, | ||
async headers() { | ||
return [ | ||
{ | ||
source: '/en-US/add-header', | ||
headers: [ | ||
{ | ||
key: 'x-hello', | ||
value: 'world', | ||
}, | ||
], | ||
}, | ||
{ | ||
source: '/nl/add-header', | ||
headers: [ | ||
{ | ||
key: 'x-hello', | ||
value: 'world', | ||
}, | ||
], | ||
}, | ||
{ | ||
source: '/add-header', | ||
headers: [ | ||
{ | ||
key: 'x-hello', | ||
value: 'world', | ||
}, | ||
], | ||
}, | ||
] | ||
}, | ||
} |
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,19 @@ | ||
export default function NotFound(props) { | ||
return ( | ||
<> | ||
<h1 id="not-found">This page could not be found | 404</h1> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
</> | ||
) | ||
} | ||
|
||
export const getStaticProps = ({ locale, locales, defaultLocale }) => { | ||
return { | ||
props: { | ||
locale, | ||
locales, | ||
defaultLocale, | ||
is404: true, | ||
}, | ||
} | ||
} |
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,19 @@ | ||
if (typeof window !== 'undefined') { | ||
window.caughtWarns = [] | ||
|
||
const origWarn = window.console.warn | ||
const origError = window.console.error | ||
|
||
window.console.warn = function (...args) { | ||
window.caughtWarns.push(args.join(' ')) | ||
origWarn(...args) | ||
} | ||
window.console.error = function (...args) { | ||
window.caughtWarns.push(args.join(' ')) | ||
origError(...args) | ||
} | ||
} | ||
|
||
export default function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
} |
32 changes: 32 additions & 0 deletions
32
test/integration/i18n-support-base-path/pages/amp/amp-first.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,32 @@ | ||
import { useAmp } from 'next/amp' | ||
import { useRouter } from 'next/router' | ||
|
||
export const config = { | ||
amp: true, | ||
} | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<p id="is-amp">{useAmp() ? 'yes' : 'no'}</p> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
<p id="router-locale">{router.locale}</p> | ||
<p id="router-locales">{JSON.stringify(router.locales)}</p> | ||
<p id="router-query">{JSON.stringify(router.query)}</p> | ||
<p id="router-pathname">{router.pathname}</p> | ||
<p id="router-as-path">{router.asPath}</p> | ||
</> | ||
) | ||
} | ||
|
||
export const getServerSideProps = ({ locale, locales }) => { | ||
return { | ||
props: { | ||
locale, | ||
locales, | ||
}, | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/integration/i18n-support-base-path/pages/amp/amp-hybrid.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,23 @@ | ||
import { useAmp } from 'next/amp' | ||
import { useRouter } from 'next/router' | ||
|
||
export const config = { | ||
amp: 'hybrid', | ||
} | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
|
||
return ( | ||
<> | ||
<p id="another">another page</p> | ||
<p id="is-amp">{useAmp() ? 'yes' : 'no'}</p> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
<p id="router-locale">{router.locale}</p> | ||
<p id="router-locales">{JSON.stringify(router.locales)}</p> | ||
<p id="router-query">{JSON.stringify(router.query)}</p> | ||
<p id="router-pathname">{router.pathname}</p> | ||
<p id="router-as-path">{router.asPath}</p> | ||
</> | ||
) | ||
} |
Oops, something went wrong.