Redirect not working
Answered
Transvaal lion posted this in #help-forum
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(
}}
>
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
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
5 Replies
@Transvaal lion "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
you could use
useRouter from 'next/navigation insteadAnswer
Transvaal lionOP
ah i see
will try that ty
works ty