So I'm talking about any Router function from beforeRouter() to router(). Every router function fires twice within a gap of milliseconds (on the backend).
Example:
import {redirect} from 'wix-router';
export function form_Router(request) {
console.log(request); //fired twice
return redirect('https://www.google.com');
}
I'm giving my current scenario. I have a html form embedded inside an email and the form action attribute is set to use the 'get' method to submit the form details. The url is like https://www.mysite.com/form/submit & I have the above router code on my routers.js file.
This will allow me to capture the details of the user on the back end (which they filled inside the email) and instantly redirect them to a Success page on the front end.
I will use the captured details to make an API call to an external platform but the thing is if the function is firing twice then the API call will be made twice. I thought about using idempotency key but it doesn't matter because the function will just generate 2 different keys.
Any hacks, solutions or workarounds?
Hey Shan, I contacted one of the devs who works with routers for clarification.
I've used routers before and I don't recall having this issue. Either I was too dense to notice, or it wasn't happening, or it was happening but didn't matter. In any case, this is an intereting issue and I hope that I can get some info on this.