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

Dynamic route does not parse params correctly when unencoded #34176

Closed
kudlajz opened this issue Feb 10, 2022 · 2 comments
Closed

Dynamic route does not parse params correctly when unencoded #34176

kudlajz opened this issue Feb 10, 2022 · 2 comments
Labels
bug Issue was opened via the bug report template.

Comments

@kudlajz
Copy link

kudlajz commented Feb 10, 2022

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
Binaries:
  Node: 17.1.0
  npm: 8.1.2
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.0.10
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.10

What version of Node.js are you using?

17.1.0

What browser are you using?

Chrome

What operating system are you using?

macOS 11.5.2

How are you deploying your application?

next start

Describe the Bug

When using getServerSideProps, context.params is undefined when unencoded URL path is the same as the dynamic route's name.

Consider having a route called [slug].tsx.

If you access /[slug], context.params equals undefined ✖️
If you access /%5Bslug%5D, context.params equals { slug: '[slug]' } ✔️
If you access /foo[slug], context.params equals { slug: 'foo[slug]' } ✔️
If you access /[slug]foo, context.params equals { slug: '[slug]foo' } ✔️
If you access /[uuid], context.params equals { slug: '[uuid]' } ✔️

Minimal working example: https://github.com/kudlajz/nextjs-dynamic-route

Expected Behavior

For /[slug] URL path, context.params should be correctly defined as { slug: '[slug]' }

To Reproduce

  1. Create a dynamic route, e.g. pages/[slug].tsx
  2. Define getServerSideProps function
  3. Access /[slug] in your application (make sure the brackets are not encoded)
  4. Check value of context.params inside getServerSideProps
@kudlajz kudlajz added the bug Issue was opened via the bug report template. label Feb 10, 2022
@balazsorban44
Copy link
Member

Hi, this has been fixed on canary already (#33808), please upgrade or wait for the next latest release.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 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

2 participants