Humble Opinion - Wix Routers Are Not Developed To Their Full Potential

#unpopularOpinion

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.

Why do you need it to fire once: To expedite processing time I plan to submit a form via a router by sending values as URL parameters - something like https://mysite.com/form?name=James&email=URL_ENCODED_EMAIL&planet=Earth%20Planet

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 :pray:

1 Like

Hi @Shan, I do agree with you, routers are great tools to develop advanced features and it could even better with only a few additions.

On top of what you suggested, I would like to add more info in Wix router request such as:

  1. current language

  2. site version

  3. View mode (preview, live)

View mode will really help for developers

Hi @Shan and @plomteuxquentin ,

Thank you for sharing your thoughts, and apologies for the late replay.

With your permission, I’ll break my answer into points -

  1. Routers are running twice: It’s a Bug. We’ve raised its priority and hopefully, it will be solved soon.

  2. 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?

  3. Add country/language/site version/View mode to the Router: Interesting ideas. I’ll take it with the team, and will update going forward.

  4. 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.

@shiran-kohai , regarding #1, could you please let us know once it’s fixed (only if you remember of course)?

Of course.

@shiran-kohai

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.

@shantanukumar847 what do you mean by that? It’s already enabled.

@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.

@shiran-kohai is the double-running issue already fixed? (I need it for oauth2)