Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the redirect function from SvelteKit.
Svelte
import { [1] } from '@sveltejs/kit';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' or 'goto' which are client-side navigation functions.
Forgetting to import the redirect function.
✗ Incorrect
The redirect function is imported from '@sveltejs/kit' to perform server-side redirects in actions.
2fill in blank
mediumComplete the action function to throw a redirect with status 303 to '/dashboard'.
Svelte
export const POST = async () => {
throw [1](303, '/dashboard');
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using client-side navigation functions inside server actions.
Not throwing the redirect but returning it.
✗ Incorrect
Throwing redirect(303, '/dashboard') inside an action causes a server-side redirect to that path.
3fill in blank
hardFix the error in the action by correctly throwing a redirect to '/home' with status 302.
Svelte
export const POST = async () => {
throw [1](302, '/home');
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning redirect instead of throwing it.
Throwing redirect without calling it as a function.
✗ Incorrect
You must throw the result of calling redirect(302, '/home') to perform the redirect correctly.
4fill in blank
hardFill both blanks to import redirect and throw a 307 redirect to '/profile' inside an action.
Svelte
import { [1] } from '@sveltejs/kit'; export const POST = async () => { throw [2](307, '/profile'); };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and throw.
Not throwing the redirect.
✗ Incorrect
You import redirect and then throw redirect(307, '/profile') to perform the redirect inside the action.
5fill in blank
hardFill all three blanks to import redirect, throw a 301 redirect to '/login', and export the POST action.
Svelte
[1] { [2] } from '@sveltejs/kit'; export const POST = async () => { throw [3](301, '/login'); };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' instead of 'redirect'.
Not throwing the redirect function call.
✗ Incorrect
You import redirect, then throw redirect(301, '/login') inside the POST action to redirect properly.