I think Wix Router is an under developed API which has massive potential. I have a couple of points to try to support my statement.
First thing is the bug that runs the router function twice. It will be very helpful to allow the function to only run on server as opposed to running it on server + page. For instance:
export function form_Router(request) {
console.log(request); //firing twice
return redirect('https://www.mysite.com/form-submitted');
}
I expect the console.log to be fired only once but it always fires twice.
And I process the submission on the backend while immediately redirecting the user to the success page - no time wasted on waiting for page to render and then corvid code to execute.
This is just one example there are many more like sending events/transactions to Google Analytics Enhanced Ecommerce & processing Stripe Connect Merchant Account creation for marketplaces.
What else could Wix Routers do:
Open Wix Routers to All Pages instead of just Dynamic Pages
Add country to Wix Router Request Object (Less Important)
Users will be able to block access by IP
Users will be able to redirect users to country specific subdomains/sites
More ability to add Schema to better allow search engines to understand the content, I know we can use the Advanced SEO panel but many times the content needs to be dynamic - not constant
Routers are bugged on Dynamic Pages
I have a site where I have afterRouter() which returns schema for Google Job Post Schema and it works perfectly - see evidence. As you can see my job postings are reflected on Google due to the schema and Google Structured Data Testing Tool returns the Schema perfectly.
But on other 2 sites the code doesnât work - same router, exact same code, same values but nothing the Structured Data Testing Tool does not find the schema. I brought this up with Wix Devs a while back and I was told that for the router to work it must be created from the site structure bar by selecting âAdd Routerâ but how come on one site where I did not do that and straightaway created a dynamic page from the database âAdd Dynamic Pageâ option it worked and on other sites its not working. From my view, it seems to be an issue.
Would like to see this API receive more attention in 2021 sâil vous plait
Thank you for sharing your thoughts, and apologies for the late replay.
With your permission, Iâll break my answer into points -
Routers are running twice: Itâs a Bug. Weâve raised its priority and hopefully, it will be solved soon.
Open Wix Routers to All Pages instead of just Dynamic Pages: Just to make sure that I understand correctly - do you mean that you want us to enable a redirect to any site page from a router and not just to a dynamic page?
Add country/language/site version/View mode to the Router: Interesting ideas. Iâll take it with the team, and will update going forward.
Bugs - not quite sure that I understand the exact UC. You wrote that you brought it up with the Dev team a while back. If possible - please add me to the thread.
Open Wix Routers to All Pages instead of just Dynamic Pages:Just to make sure that I understand correctly - do you mean that you want us to enable a redirect to any site page from a router and not just to a dynamic page?
Yes, thatâs what I meant.
What do you think about it? Do you think its a function that can add value to sites? If we have this I think we can enable redirects to any site page based on their location/membership status/url parameter without having to wait for the page to render and corvid code to run. This will result in much faster transitions and enhance user experience.
@jonatandor35 I donât understand what you mean. Routers are not available for site pages.
import {redirect} from "wix-router";
export function code_Router(request) { //Code router
console.log(request);
return redirect("https://www.wix.com/corvid/reference/wix-router/introduction");
}
export function url_Router(request) { //Site page
console.log(request); //Does not work
return redirect("https://www.wix.com/corvid/reference/wix-router/introduction"); //Does not work
}
@shantanukumar847 Iâm not sure what youâre saying and maybe itâs a matter of terminology.
If you create a new router page you can redirect to any page you like, and neither the router page nor the target page has to be âdynamicâ (i.e. none of them has to be dynamically based on database values). But maybe you meant to something else.