How to redirect page after call to endpoint's del()? #4684
-
Hey everyone. I wonder if I can ask for some advice on an issue which is puzzling my team. We have a page ( We started off with an Our question is about what happens next. We observe that SvelteKit tries to re-render the user's profile page again, and thus calls This aligns with the comments in the code example here: https://kit.svelte.dev/docs/routing#endpoints-post-put-patch-delete:
However, this doesn't really make sense for So, to work around this, I need to issue a redirect. I initially tried it in the endpoint:
But this doesn't work - the This matches what I see from @babichjacob here (#3861) and @mrkishi here (#4466) - they explain that we need to either handle the The latter method, using HTML, works fine. It's a desirable direction for us to move in, but I don't think we're ready to embrace native HTML forms across the board in our app yet - we're converting a large app from Angular to Svelte, and have click handlers all over the place! So we'd love to achieve this using fetch. But the problem I can't solve is that after The eventual question: would you consider this (calling |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I worked out the problem - I needed to set a |
Beta Was this translation helpful? Give feedback.
I worked out the problem - I needed to set a
accept: application/json
header on the call todel()
to ensure I got a JSON response, rather than HTML (which by necessity performs an SSR, which needs to callget()
to load the data for the page). Thanks to 7nik on Discord for helping with this one.