0
0
Svelteframework~10 mins

Redirect from actions in Svelte - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aredirect
Bnavigate
Cgoto
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' or 'goto' which are client-side navigation functions.
Forgetting to import the redirect function.
2fill in blank
medium

Complete 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'
Afetch
Bnavigate
Cgoto
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using client-side navigation functions inside server actions.
Not throwing the redirect but returning it.
3fill in blank
hard

Fix 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'
Athrow redirect()
Bredirect
Cthrow redirect
Attempts:
3 left
💡 Hint
Common Mistakes
Returning redirect instead of throwing it.
Throwing redirect without calling it as a function.
4fill in blank
hard

Fill 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'
Aredirect
Bnavigate
Dgoto
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for import and throw.
Not throwing the redirect.
5fill in blank
hard

Fill 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'
Aimport
Bredirect
Dnavigate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'navigate' instead of 'redirect'.
Not throwing the redirect function call.