QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.2k stars 54 forks source link

Config rewrites not working #301

Closed thainv92 closed 7 months ago

thainv92 commented 7 months ago

Describe the bug Rewrites config working when use middleware next-international

To Reproduce Steps to reproduce the behavior: Your demo: https://codesandbox.io/p/devbox/next-international-app-router-forked-j9wq2k?file=%2Fpackage.json%3A17%2C4-18%2C36

  1. add config
    
    /** @type {import('next').NextConfig} */
    const nextConfig = {
    async rewrites() {
    return [
      {
        source: "/blog",
        destination: "https://example.com/blog",
      },
      {
        source: "/blog/:slug",
        destination: "https://example.com/blog/:slug", // Matched parameters can be used in the destination
      },
    ];
    },
    };

module.exports = nextConfig;


2. Go to: https://j9wq2k-3000.csb.app/en/blog
3. Error display

**Expected behavior**
Working rewrite well

**About (please complete the following information):**
 - "next": "13.5.4",
 - "next-international": "^1.1.4"
navata commented 7 months ago

@QuiiBz I really hope to receive support from your reply.

QuiiBz commented 7 months ago

Sorry for the delay, I started a new job recently. You have to update the source field to take into account the locale dynamic param:

/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: "/:locale/blog",
        destination: "https://example.com/blog",
      },
      {
        source: "/:locale/blog/:slug",
        destination: "https://example.com/blog/:slug", // Matched parameters can be used in the destination
      },
    ];
  },
};

I've tested it here and it's working as expected when navigating to /en/blog or /blog directly.