Dynamic route in NextJS for username /@[username]
Unanswered
Madeiran sardinella posted this in #help-forum
Madeiran sardinellaOP
Wondering how one would go about doing this where a dynamic route starts with @ symbol. I can't seem to figure it out, the only alternative would be to have all usernames in my database start with @, i'm trying to avoid this.
5 Replies
Asian black bear
You’d have to escape it but it’s still broken IIRC. Also using @ in URLs is a recipe for disaster. Just don’t.
@Madeiran sardinella Wondering how one would go about doing this where a dynamic route starts with @ symbol. I can't seem to figure it out, the only alternative would be to have all usernames in my database start with @, i'm trying to avoid this.
app/[usernameWithAt]/page.tsxfunction Page({ params }) {
const username = usernameWithAt.slice(1);
// do stuff
}@Asian black bear You’d have to escape it but it’s still broken IIRC. Also using @ in URLs is a recipe for disaster. Just don’t.
it's only broken for static routes, for dynamic routes it works fine
@Asian black bear You’d have to escape it but it’s still broken IIRC. Also using @ in URLs is a recipe for disaster. Just don’t.
Madeiran sardinellaOP
yeah this seems like the best way to go about it, simplest
ty 🫡