Next.js Discord

Discord Forum

Redirect not working

Answered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
"use client";

import { redirect } from "next/navigation";

export default function LegoButton({ id }: { id: string }) {
return (
<button
type="button"
className="absolute inset-0 focus:outline-none"
onClick={() => {
console.log(id);
redirect(/l/${id});
}}
>
hi
<span className="sr-only">Open</span>
</button>
);
}


I have htis simple button which i want to redirect to another page but it doesn't work. console.log works though
Answered by Ray
you could use useRouter from 'next/navigation instead
View full answer

5 Replies