Next.js Discord

Discord Forum

Parallel Routes Error handling.

Unanswered
Japanese common catfish posted this in #help-forum
Open in Discord
Japanese common catfishOP
Hi guys, im trying with the error boundary stuff in nextjs. I found that if i use the reset function without router.refresh() it wont retry my server component to re-render, unless i refresh my page. As the solution below, can work for normal page, but if i using Parallel Route, if one of the segment is encounter error, and how can i retry only that segment instead of the whole page?

"use client"; // Error boundaries must be Client Components
export default function Error({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
const router = useRouter();
return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => {
startTransition(() => {
router.refresh();
reset();
});
}
}
>
Try again
</button>
</div>
);
}

0 Replies