vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.83k stars 26.96k forks source link

SSG With localization doesn't create defaultLocale correctly #27251

Closed dan2kx closed 3 years ago

dan2kx commented 3 years ago

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

14.17.3

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Other

Describe the Bug

I have added i18n support and on page with static paths the defaultLocale is created incorrectly i think.

  i18n: {
    locales: ["en-US", "es-US"],
    defaultLocale: "en-US",
  },

the files created by the blog/[slug].tsx are:

blog/en-US/slug...
blog/es-US/slug...

Expected Behavior

i would expect the pages created to be as follows

blog/slug...
blog/es-US/slug...

pages without getStaticPaths are created as expected

To Reproduce

1 create a page with static paths like so

// pages/blog/[slug].js
export const getStaticPaths = ({ locales }) => {
  return {
    paths: [
      { params: { slug: 'post-1' }, locale: 'en-US' },
      { params: { slug: 'post-1' }, locale: 'es-US' },
    ],
    fallback: true,
  }
}

2 run build

npm run build 

the files created are as listed above

ijjk commented 3 years ago

Hi, it looks like you are referencing the output location in the .next/server folder, if so this it is expected to be output under the locale prefix inside of that folder. Next.js handles routing to the defaultLocale automatically so that it is available at the root without the locale prefix.

I'm going to close this since it isn't a bug and appears to be working correctly. Feel free to reply with additional info if needed.

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.