Non-letter characters in route parameters. (e.g '@')
Answered
not-milo.tsx posted this in #help-forum
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
Is this intentional or is it a bug?
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 ([
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.26 Replies
@not-milo.tsx 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?
Depending on how you set your page up. If you set it up correctly then it is a bug
This is the page code:
The db already stores prefixed usernames so I don't need to add it in manually.
And this is the folder structure:
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.tsxPretty 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 seei'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
This is going to be a fun one
Don't mind me... 👀
I should have read the docs ([
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
