Skip to content

localePrefix only receive 'always', instead as mentioned on the page (https://next-intl.dev/docs/routing/configuration#localeprefix) #2096

@irwansyafani

Description

@irwansyafani

Description

I just installed the package just 4 hours after updated deployment.

DISCLAIMER: My Next JS Folder Structure (App Router)

src
  proxy.js // I tried to put this file on the root and inside folder src
  /i18n
    /messages
      ...the language.json
    navigation.js
    request.js
    routing.js

Simply, I wanted to make my page accessible for both side /:page or /:locale/:page. When I read the documentation I found that I can make it by setting up the localePrefix inside /src/i18n/routing.js:

import {defineRouting} from 'next-intl/routing';
 
export const routing = defineRouting({
  locales: ['en', 'zh'],
  defaultLocale: 'en',
  localeDetection: true,
  localeCookie: {
    name: 'NEXT_LOCALE',
    maxAge: 60 * 60 * 24 * 365
  },
  localePrefix: 'as-needed' // the problem I found
});
// next.config.mjs
...
const withNextIntl = createNextIntlPlugin();
export default withNextIntl(nextConfig);

However, after checking the autocomplete it only receive always instead of others. At first, I thought it was just the autocomplete configuration. After completing all the setup, it turns error while accessing the page without :locale. Actually no returning any error or something alike, it just returns to not-found page.

Can anyone help to explain where did I miss? or is this the bug from the package?

Verifications

Mandatory reproduction URL

App Router

Reproduction description

Steps to reproduce:

  1. Open the docs
  2. Read on https://next-intl.dev/docs/routing/configuration#localeprefix
  3. See error: no error but doesn't work at docs mentioned.

Expected behaviour

On page: https://next-intl.dev/docs/routing/configuration#localeprefix
Expected: make the page accessible with and without locale on the URL (OK: /:any-path-of-the-page and /:locale/:any-path-of-the-page)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions