Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

354
Vistas
Adding symbol (e.g. @) in front of slug in NextJS route

I am trying to add @ in front of a slug URL. For example: https://example.com/@username.

I tried @[username].js but that is not working.

Is this even possible?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try using rewrites and some regex. Next.js uses path-to-regexp under the hood.

  async rewrites() {
    return [
      {
        source: '/:userId(@[a-zA-Z0-9]+)/:id*',
        destination: "/user/:userId/:id*",
      }
    ]
  }

On client side use next/link:

<Link href={`@${userId}`}>
  <a>user</a>
</Link>
over 4 years ago · Santiago Trujillo Denunciar

0

In your backend when you handle users, put the @ in the users' usernames. Then, simply treat the usernames as if they were plain text slugs. This works because @ is allowed in URLs, just like a, b or c.

Working example on StackBlitz.

pages/index.js:

import Link from 'next/link'

const username = '@foobar' // hardcoded example username, this will be recieved from your backend

export default function Index() {
    return (
        <Link href={username}>
            <a>{username}</a>
        </Link>
    )
}

pages/[username].js:

import { useRouter } from 'next/router'

export default function Username() {
    const router = useRouter()
    const { username } = router.query

    return <h1>User: {username}</h1>
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda