amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Pathnames with 2 dynamics values of the same name require 2 different params #1236

Closed Rheaparks closed 3 months ago

Rheaparks commented 3 months ago

Description

I need to use the same dynamic param twice. But even if it is the same param, the getPathname() is asking two params. I can't obviously enter the same param twice… Is it my mistake?

Here is the pathname code:

    "/seo/things-to-do/[countrySlug]": {
      en:"/[countrySlug]/things-to-do-[countrySlug]",
      fr:"/[countrySlug]/que-faire-[countrySlug]",
    },

The error:

Error: Insufficient params provided for localized pathname.
Template: /[countrySlug]/que-faire-[countrySlug]
Params: {"countrySlug":"france"}

Verifications

Mandatory reproduction URL

https://github.com/amannn/next-intl-bug-repro-app-router

Reproduction description

Steps to reproduce:

  1. On environment { Pathnames } next-intl/routing

  2. Create a pathname with config or navigation.ts like this:

    "/seo/things-to-do/[countrySlug]": {
      en:"/[countrySlug]/things-to-do-[countrySlug]",
      fr:"/[countrySlug]/que-faire-[countrySlug]",
    },
  3. Create app > [locale] > seo > things-to-do > [countrySlug] > page.tsx

  4. Call:

    const path = getPathname({
    locale: locale,
    href: {
      pathname: "/seo/things-to-do/[countrySlug]"
      params: { countrySlug: "france" }
    },
    } as any);
  5. See error:

    Error: Insufficient params provided for localized pathname.
    Template: /[countrySlug]/que-faire-[countrySlug]
    Params: {"countrySlug":"france"}

Expected behaviour

We enter only one param, since it is the same param called twice.

amannn commented 3 months ago

Thanks for the report! A fix is coming in https://github.com/amannn/next-intl/pull/1259