Hi
I’m using the below code to redirect a dynamic page when the selected language is not English. It seems pretty simple but I think I might be missing something because it’s not working.
The code is in the routers.js file
import {ok,redirect} from ‘wix-router’;
export function Schengen_visa_beforeRouter(request) {
if (request.query.lang===“en”) { return ok()
}
else return [redirect(“https://www.tripawayjo.com ”)](redirect(“https://www.tripawayjo.com ”)
}
)
[}](redirect(“https://www.tripawayjo.com ”)
}
)
Thanks
Shan
January 25, 2020, 4:39pm
2
Routers can only be used on the backend code. You will need to use Wix Location .
Hi Shan
Yes, I understand, I’m using this code in the routers.js file. That’s a backend code no?
Shan
January 25, 2020, 5:23pm
4
[UPDATED CODE]
Ok so if the site language is ‘en’ then the query.lang parameter does not exist in the request.
But if it is another language then the query.lang parameter will exist. Your url will need to end with something like ?lang=es
So maybe something like:
import {redirect, next} from 'wix-router';
export function prefix_beforeRouter(request) {
let query = request.query;
if(!query) {
return next();
} else {
if(query.lang !== 'en') {
return redirect('https://www.google.com/', 302);
} else {
return next();
}
}
}
Thanks Shan. Still not working though. I guess the dynamic page router is still trying to retrieve the same page, with empty parameters.
Shan
January 25, 2020, 5:49pm
6
Show me the exact code you have on the router.js file.
Also, have you tested it live?
import {redirect, next} from ‘wix-router’;
export function Schengen_visa_beforeRouter(request) {
let query = request.query;
if (!query) {
return next();
} else {
if (query.lang !== ‘en’) {
return redirect(‘https://www.google.com/ ’, 302);
} else {
return next();
}
}
}
Shan
January 25, 2020, 6:00pm
9
Based on the console on your screenshot I think its working, have you tried it on the live site?
Nope, only in preview mode. As edits are not ready yet.
Shan
January 25, 2020, 6:01pm
11
It will work on the live site. I’m sure of it.
Shan
January 25, 2020, 6:37pm
14
its working fine for me. unless you have additional code regarding this page it should work.
try replacing next() with ok()
import {redirect, ok} from ‘wix-router’;
export function Schengen_visa_beforeRouter(request) {
let query = request.query;
if (!query) {
return ok();
} else {
if (query.lang !== ‘en’) {
return redirect(‘https://www.tripawayjo.com/ ’, 302);
} else {
return ok();}}}
What I’m trying to accomplish here is based on language selected, route is defined to one of two dynamic pages.
Hello. Maybe you know how to redirect some of products to another page(in site)
like I have product table and some of this table must redirected to main page.
Im already spent 3 days for it((