import {session} from ‘wix-storage’;
import {redirect} from ‘wix-router’;
export function Members_afterRouter(request, response) {
return redirect(“http://www.google.com”);
}
All works until I add the first line: import {session} from ‘wix-storage’;
If I add this line, redirect doesn’t work, why ?
thx in advance
hi Mauro,
router.js is where you write code that handles incoming page URLs.
as such, it is running in the backend side of your site.
wix-router is a backend module that you import into router.js.
however, wix-storage is a frontend module.
you use it to work with the browser’s local storage / session storage mechanism.
hence, the two don’t mix.
when you’re trying to import a frontend module in backend code, the system can’t load it and the execution breaks.
hope this helps.
Hi Ziv, thx so much, I would not have got it.
Only one question if I can.
I would insert some logic in router.js, but I’d need some values that I could process in front-end.
Is it possible ?
Or, despite of, what could I process in backend ?
eg. my case: I need to know if the User logged is present (wixData.query) in a particular collection, and jump to a different page based of some propreties of the User.
Above all, perhaps I’m not able to decipher the router() API instructions:
I’m able to get works following:
OK
import {redirect} from ‘wix-router’;
export function Members_afterRouter(request, response) {
return redirect(“https://costieraslow.wixsite.com/ilmiosito/test”);}
but NOT the following:
import {ok} from ‘wix-router’;
export function Members_Router(request) {
return redirect(“test”);}
OR
import {ok} from ‘wix-router’;
export function Members_afterRouter(request, response) {
return ok(“test”);}
What is wrong please ? Thanks in advance
MAuro
I believe that you need to add " /ilmiosito/test " if that’s the correct url. This is because you are on a free plan and when you reroute to test I believe it will try to find domain.com/test and that won’t work in your scenario. Just a thought.
Hi Andreas, thanks for your help,
I tried your solution hoping in some magician,
but of course it doesn’t work,
the wix code api reference are clear:
Prefix and path: