ciscoheat / sveltekit-flash-message

Send temporary data after redirect, usually from endpoints. Works with both SSR and client.
https://www.npmjs.com/package/sveltekit-flash-message
MIT License
246 stars 5 forks source link

No redirect option to another page within form action? #36

Closed accesstechnology-mike closed 3 months ago

accesstechnology-mike commented 4 months ago

This example doesn't allow for a redirect to another location:

https://github.com/ciscoheat/sveltekit-flash-message?tab=readme-ov-file#form-action-example

Form action example

src/routes/todos/+page.server.ts

import { redirect } from 'sveltekit-flash-message/server';

export const actions = {
  default: async ({ request, locals, cookies }) => {
    const form = await request.formData();

    await api('POST', `/todos/${locals.userid}`, {
      text: form.get('text')
    });

    const message = { type: 'success', message: "That's the entrepreneur spirit!" } as const;
    throw redirect(message, cookies);
  }
};

How do I redirect to another page using this library, within a formaction?

shyakadavis commented 4 months ago

Hello, @accesstechnology-mike

I don't know about your specific use case, but for me, something like this works if I'm redirecting to a different page:

redirect(303, '/my/projects', { type: 'success', title: 'Project created successfully.' }, event);
ciscoheat commented 4 months ago

The complete usage for redirect is right above the example.