Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite wildcard path not working for nested routes #24288

Closed
keslert opened this issue Apr 20, 2021 · 3 comments
Closed

Rewrite wildcard path not working for nested routes #24288

keslert opened this issue Apr 20, 2021 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@keslert
Copy link

keslert commented Apr 20, 2021

What version of Next.js are you using?

10.1.3

What version of Node.js are you using?

14.16.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

Using the following wildcard path matching doesn't match nested routes.

{
  source: "/@:username*",
  destination: "/u/:username*",
}

This works: /@vercel
This doesn't work: /@vercel/settings

If I change to the following:

{
  source: "/@/:username*",
  destination: "/u/:username*",
}

This works: /@/vercel
This works: /@/vercel/settings

Expected Behavior

The wildcard path matching should work on nested routes.

To Reproduce

// next.config.js
module.exports = {
  future: {
    webpack5: true,
  },
  async rewrites() {
    return [
      {
        source: "/@:username*",
        destination: "/u/:username*",
      },
    ]
  }
}
@keslert keslert added the bug Issue was opened via the bug report template. label Apr 20, 2021
@kylemarshall18
Copy link
Contributor

kylemarshall18 commented Apr 21, 2021

@keslert I believe you have to use regex path matching to get the expected behaviour (or as a work around):

async rewrites() {
    return [
      {
        source: '/:username(@.*)',
        destination: '/u/:username',
      },
    ]
  },

This will match /@vercel & /@vercel/settings but not /vercel or /vercel/settings

@ijjk
Copy link
Member

ijjk commented Apr 28, 2021

Closing as the solution in #24288 (comment) is correct as using :path* with a leading character changes the behavior for non-regex matching.

@ijjk ijjk closed this as completed Apr 28, 2021
@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants