KEMBAR78
Rewrite adds query param when re-appending a matched path param to the destination · Issue #15626 · vercel/next.js · GitHub
Skip to content

Rewrite adds query param when re-appending a matched path param to the destination #15626

@sventschui

Description

@sventschui

Bug report

Describe the bug

A rewrite from /source/:route* to http://my-api-server.example.org/destination/:route* forwards a request sent to /source/foo to http://my-api-server.example.org/destination/foo?route=foo. The extra query param will lead to issues especially with API servers as in REST this might represent a filter criteria.

To Reproduce

  1. Create a new next app

  2. Create a custom next.config.js:

module.exports = {
  async rewrites() {
    return [
      {
        source: "/api/:route*",
        destination: "https://postman-echo.com/:route*",
      },
    ];
  },
};
  1. Start next: yarn next dev

  2. Open up http://localhost:3000/api/get

  3. The results includes "url":"https://postman-echo.com/get?route=get"

Expected behavior

Params that are added to the destination path should not be included as a query param.

  1. The results includes "url":"https://postman-echo.com/get"

Screenshots

n/a

System information

  • Version of Next.js: 9.5.0
  • Version of Node.js: n/a

Additional context

n/a

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions