Next.js Discord

Discord Forum

route starting with @

Answered
Inca Dove posted this in #help-forum
Open in Discord
Inca DoveOP
How do i make a route that starts with @? i tried %40, i tried @ and nothing worked, no luck looking on docs
Answered by Giant panda
It's a known issue, there is one open on GitHub, but I can't find it quickly. Regardless, I highly suggest to not use special chars in routes. It's often pointless and makes things needlessly complicated.
View full answer

5 Replies

Giant panda
It's a known issue, there is one open on GitHub, but I can't find it quickly. Regardless, I highly suggest to not use special chars in routes. It's often pointless and makes things needlessly complicated.
Answer
Inca DoveOP
well, unfortunately my website requires it but i might just use a catch all route
[slug]
  @team
    page.tsx
  @analytics
    page.tsx
  layout.tsx

//layout.tsx
import { notFound } from "next/navigation";
export default function Home({
  params,
  team,
  analytics,
}: {
  params: { slug: string };
  analytics: React.ReactNode;
  team: React.ReactNode;
}) {
  const slug = params.slug.replace(/%40/g, "");

  if (slug === "team") {
    return team;
  } else if (slug === "analytics") {
    return analytics;
  } else return notFound();
}
now u can navigate to /@team and /@analytics
your better off using rewrites in next config than that tbh (but ig that could work)