Next.js Discord

Discord Forum

Non-letter characters in route parameters. (e.g '@')

Answered
not-milo.tsx posted this in #help-forum
Open in Discord
When generating route parameters I see that whether you have a special character at the beginning of the parameter or not it doesn't matter when navigating to that particular page.

For example if I have a app/[username]/page.tsx and all usernames are prefixed with the @ character, similarly to what Mastodon does, I can still navigate to a user's profile even without the prefix. https://mysite.com/@milo.me and https://mysite.com/milo.me return the same page even tho the second url doesn't appear in the generated parameters.

Is this intentional or is it a bug?
Answered by not-milo.tsx
Don't mind me... 👀

I should have read the docs ([dynamicParams](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams)) more carefully when I opened that issue.
View full answer

26 Replies

This is the page code:

import { prisma } from '~lib/prisma'

export async function generateStaticParams() {
  const users = await prisma.public_users.findMany({
    select: {
      username: true,
    },
  })

  return users.map((user) => ({
    username: user.username,
  }))
}

export default function Page({
  params: { username },
}: {
  params: { username: string }
}) {
  return <div>User: {decodeURIComponent(username)}</div>
}


The db already stores prefixed usernames so I don't need to add it in manually.

And this is the folder structure:

/app
  /(dashboard)
    /[username]
      /page.tsx
Pretty simple stuff
Are you sure you dont have middleware or something similar that may perform unnecessary redirects?
If not, it looks like a bug to me
Please report
(Please check also whether _ suffers from the same problem)
@joulev Are you sure you dont have middleware or something similar that may perform unnecessary redirects?
No, I just have a middleware that's only refreshing a supabase session
then yeah it looks like a bug to me
@joulev (Please check also whether _ suffers from the same problem)
Yup. _milo.me also renders the page...
wow
100% a bug now
just to test, try making a user @not-found, then access /_not-found, then access a random 404 page, what do you see
i'm quite interested
because afaik /_not-found is the path of the global 404
@joulev 100% a bug now
Good to know it's a bug. I'll open a new issue on GitHub then
@joulev i'm quite interested
Give me a sec
Dear god ahaha
Now all not found pages render a user page
:Kek:
congrats, you just found a very nasty nextjs bug
a very funny bug as well
This is going to be a fun one
Don't mind me... 👀

I should have read the docs ([dynamicParams](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams)) more carefully when I opened that issue.
Answer