Next.js Discord

Discord Forum

Redirecting

Answered
Shaurya posted this in #help-forum
Open in Discord
what is the best way to create redirect routes? like when I go to /social/discord it recirects me to the link I've set

I could make a component like
import { useEffect } from "react"
import { useRouter } from "next/router"

export default function RedirectPage({ link }: Props) {
  const router = useRouter()

  useEffect(() => {
    router.replace(link)
  }, [])

  return null
}
and reuse this component in every redirect route, so for /social/discord
export default <RedirectPage link={myDiscordLink} />


is this the way or is there any better way to do the same?

3 Replies

anyone please help me out with this
Answer
you can just use redirect function