Recall & Review
beginner
What is the purpose of the
redirect() function in Next.js?The
redirect() function in Next.js is used to send users to a different URL or page, often after an action like login or form submission. It helps control navigation programmatically.Click to reveal answer
intermediate
Where can you use the
redirect() function in Next.js 14+?You can use
redirect() inside server components, server actions, and route handlers to perform server-side redirects before the page renders.Click to reveal answer
beginner
How do you import the <code>redirect()</code> function in a Next.js app router?You import it from <code>next/navigation</code> like this: <br><code>import { redirect } from 'next/navigation'</code>Click to reveal answer
intermediate
What happens if you call
redirect('/home') inside a server component?The user is immediately sent to the '/home' page before the current page finishes rendering. The browser URL changes and the new page loads.
Click to reveal answer
intermediate
Can you use
redirect() inside client components in Next.js?No,
redirect() is meant for server-side use. For client-side navigation, use the useRouter() hook with router.push().Click to reveal answer
Where do you import the
redirect() function from in Next.js?✗ Incorrect
The
redirect() function is imported from next/navigation in Next.js 14+.What does calling
redirect('/dashboard') inside a server component do?✗ Incorrect
Calling
redirect() inside a server component sends the user to the new URL immediately.Can you use
redirect() inside a client component?✗ Incorrect
The
redirect() function is for server-side use. Client components should use router.push().Which Next.js feature is commonly used together with
redirect() for server-side logic?✗ Incorrect
redirect() is often used inside Server Actions to redirect after server-side tasks.What is a common use case for
redirect() in Next.js?✗ Incorrect
redirect() is commonly used to send users to a new page after login or other server-side events.Explain how the
redirect() function works in Next.js and where you can use it.Think about server vs client roles in Next.js.
You got /4 concepts.
Describe the difference between using
redirect() and client-side navigation methods in Next.js.Consider when the navigation happens and which environment runs the code.
You got /4 concepts.