I have follow problem with Routers redirect function:
import {redirect, ok, notFound} from "wix-router";
export async function apartments_Router(request) {
if(request.path[0] == '')
return ok('apartments-page', request);
let queryString = '?floor=1&ap=Apartment17';
return redirect('/apartments/'+queryString, '302');
}
When I run url https://…/apartments/Apartment17/floor2
It brings me to “/apartments/” url without my queryString params. Why?
try to remove the last /
from /apartements/
Does that solve the issue?
J.D
3
- You’re better use the falsy value:
import {redirect, ok, notFound} from "wix-router";
export function apartments_Router(request) {
if(!request.path) {
return ok('apartments-page', request);
}
let queryString = '?floor=1&ap=Apartment17';
return redirect('/apartments'+ queryString, '302');
}
Everything after ? cut out by redirect() function((((
with slash or without(((
J.D
5
Try to play with it a little bit in order to locate the problem.
-
Does the redirection work well if you remove the first condition?
-
Does the redirection work if you use the full URL (https://domain.com/…)?
-
Add console.log(path), and console.log(‘step1’) etc… to your code and look at the logs in the site logs.