Recall & Review
beginner
What are conditional routes in Next.js?
Conditional routes are routes that render different pages or components based on certain conditions like user authentication or roles.
Click to reveal answer
beginner
How can you protect a page in Next.js so only logged-in users can access it?
You can check the user's authentication status in a client component or server component and redirect or show a login page if the user is not logged in.
Click to reveal answer
intermediate
Which Next.js feature helps you redirect users on the server side based on conditions?
The 'redirect()' function from 'next/navigation' allows server components to redirect users conditionally before rendering the page.
Click to reveal answer
intermediate
Why is it better to handle conditional routes in server components in Next.js 14+?
Handling conditional routes in server components improves performance and security by deciding access before sending the page to the browser.
Click to reveal answer
beginner
What is a simple way to show different content on a page based on user role in Next.js?
Fetch the user role in a server component and use conditional rendering to show different components or messages depending on the role.
Click to reveal answer
In Next.js, which function is used to redirect users on the server side?
✗ Incorrect
The redirect() function from next/navigation is used in server components to redirect users before rendering.
What is the main reason to use conditional routes in Next.js?
✗ Incorrect
Conditional routes let you show different pages or content depending on user login or roles.
Where is it recommended to check user authentication for conditional routing in Next.js 14+?
✗ Incorrect
Server components can check authentication securely and redirect before sending the page.
Which hook is NOT used for conditional routing in Next.js?
✗ Incorrect
useFetch is not a built-in Next.js hook; useRouter is used for client-side navigation.
What happens if a user is not authenticated and tries to access a protected route with conditional routing?
✗ Incorrect
Conditional routing redirects unauthenticated users to login or a safe page.
Explain how you would implement a conditional route in Next.js to restrict access to logged-in users only.
Think about where to check login status and how to redirect.
You got /4 concepts.
Describe the benefits of handling conditional routes in server components in Next.js 14 and later.
Consider what happens before the page reaches the browser.
You got /4 concepts.