Skip to content

Commit

Permalink
Merge branch 'canary' into unflag/notFound
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Oct 27, 2020
2 parents f4d4487 + 1b22a39 commit a7b7396
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/advanced-features/module-path-aliases.md
Expand Up @@ -4,6 +4,13 @@ description: Configure module path aliases that allow you to remap certain impor

# Absolute Imports and Module path aliases

<details>
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-absolute-imports">With env</a></li>
</ul>
</details>

Next.js automatically supports the `tsconfig.json` and `jsconfig.json` `"paths"` and `"baseUrl"` options since [Next.js 9.4](https://nextjs.org/blog/next-9-4).

> Note: `jsconfig.json` can be used when you don't use TypeScript
Expand Down
4 changes: 4 additions & 0 deletions docs/manifest.json
Expand Up @@ -184,6 +184,10 @@
{
"title": "Codemods",
"path": "/docs/advanced-features/codemods.md"
},
{
"title": "Internationalized Routing",
"path": "/docs/advanced-features/i18n-routing.md"
}
]
},
Expand Down
34 changes: 34 additions & 0 deletions examples/i18n-routing/.gitignore
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
23 changes: 23 additions & 0 deletions examples/i18n-routing/README.md
@@ -0,0 +1,23 @@
# Internationalized Routing

This example shows how to create internationalized pages using Next.js and the i18n routing feature. It shows a normal page, a non-dynamic `getStaticProps` page, a dynamic `getStaticProps` page, and a `getServerSideProps` page.

For further documentation on this feature see the documentation [here](https://nextjs.org/docs/advanced-features/i18n-routing)

## Deploy your own

Deploy the example using [Vercel](https://vercel.com):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/amp)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example i18n-routing i18n-app
# or
yarn create next-app --example i18n-routing i18n-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
6 changes: 6 additions & 0 deletions examples/i18n-routing/next.config.js
@@ -0,0 +1,6 @@
module.exports = {
i18n: {
locales: ['en', 'fr', 'nl'],
defaultLocale: 'en',
},
}
15 changes: 15 additions & 0 deletions examples/i18n-routing/package.json
@@ -0,0 +1,15 @@
{
"name": "i18n-routing",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"license": "MIT"
}
59 changes: 59 additions & 0 deletions examples/i18n-routing/pages/gsp/[slug].js
@@ -0,0 +1,59 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function GspPage(props) {
const router = useRouter()
const { defaultLocale, isFallback, query } = router

if (isFallback) {
return 'Loading...'
}

return (
<div>
<h1>getServerSideProps page</h1>
<p>Current slug: {query.slug}</p>
<p>Current locale: {props.locale}</p>
<p>Default locale: {defaultLocale}</p>
<p>Configured locales: {JSON.stringify(props.locales)}</p>

<Link href="/gsp">
<a>To getStaticProps page</a>
</Link>
<br />

<Link href="/gssp">
<a>To getServerSideProps page</a>
</Link>
<br />

<Link href="/">
<a>To index page</a>
</Link>
<br />
</div>
)
}

export const getStaticProps = ({ locale, locales }) => {
return {
props: {
locale,
locales,
},
}
}

export const getStaticPaths = ({ locales }) => {
const paths = []

for (const locale of locales) {
paths.push({ params: { slug: 'first' }, locale })
paths.push({ params: { slug: 'second' }, locale })
}

return {
paths,
fallback: true,
}
}
40 changes: 40 additions & 0 deletions examples/i18n-routing/pages/gsp/index.js
@@ -0,0 +1,40 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function GspPage(props) {
const router = useRouter()
const { defaultLocale } = router

return (
<div>
<h1>getServerSideProps page</h1>
<p>Current locale: {props.locale}</p>
<p>Default locale: {defaultLocale}</p>
<p>Configured locales: {JSON.stringify(props.locales)}</p>

<Link href="/gsp/first">
<a>To dynamic getStaticProps page</a>
</Link>
<br />

<Link href="/gssp">
<a>To getServerSideProps page</a>
</Link>
<br />

<Link href="/">
<a>To index page</a>
</Link>
<br />
</div>
)
}

export const getStaticProps = ({ locale, locales }) => {
return {
props: {
locale,
locales,
},
}
}
40 changes: 40 additions & 0 deletions examples/i18n-routing/pages/gssp.js
@@ -0,0 +1,40 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function GsspPage(props) {
const router = useRouter()
const { defaultLocale } = router

return (
<div>
<h1>getServerSideProps page</h1>
<p>Current locale: {props.locale}</p>
<p>Default locale: {defaultLocale}</p>
<p>Configured locales: {JSON.stringify(props.locales)}</p>

<Link href="/gsp">
<a>To getStaticProps page</a>
</Link>
<br />

<Link href="/gsp/first">
<a>To dynamic getStaticProps page</a>
</Link>
<br />

<Link href="/">
<a>To index page</a>
</Link>
<br />
</div>
)
}

export const getServerSideProps = ({ locale, locales }) => {
return {
props: {
locale,
locales,
},
}
}
31 changes: 31 additions & 0 deletions examples/i18n-routing/pages/index.js
@@ -0,0 +1,31 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function IndexPage(props) {
const router = useRouter()
const { locale, locales, defaultLocale } = router

return (
<div>
<h1>Index page</h1>
<p>Current locale: {locale}</p>
<p>Default locale: {defaultLocale}</p>
<p>Configured locales: {JSON.stringify(locales)}</p>

<Link href="/gsp">
<a>To getStaticProps page</a>
</Link>
<br />

<Link href="/gsp/first">
<a>To dynamic getStaticProps page</a>
</Link>
<br />

<Link href="/gssp">
<a>To getServerSideProps page</a>
</Link>
<br />
</div>
)
}

0 comments on commit a7b7396

Please sign in to comment.