Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to fetch default action in +page.server.ts file in SvelteKit

$
0
0

I'm using SvelteKit and I've a form on my page. As I need to manipulate the data before it is sent, I cannot use the SvelteKit's default behaviour of form submission (using action attribute).

So, according to this part of the documentation, I used a simple event listener and then the fetch function :

async function handleSubmit(e:Event) {  const formData = new FormData(e.target as HTMLFormElement);  // ... doing some stuff here  const res = await fetch("?/login", { /* plenty of stuff there */ });}

So the action named "login" in ./+page.server.ts will be executed.

I have a simple question: what path do I write (in fetch) if I want the default action to be executed, knowing that the current page is in a slug.

Do I write fetch("?/") ? (doesn't work)

Do I write fetch("?") ? (doesn't work)

Obviously I could just name it and problem solved. I'm just wondering if there is a solution and if someone has ever thought about this.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>