I need to get before onReady

Hi
I have few simple pages, and before anyone gets in, I want to redirect him to another page asking for a password. I don’t want him to see their content before he inserts password at the second page.
I made it and it works fine. The problem is that it takes few seconds and meanwhile the man can see the first page.
I assume that if I put the code before onReady() it can work better, but I didn’t find anywhere I can write it.

Any ideas?

my code:

$w.onReady( function () {
let pass = local.getItem(“password”);

if (pass !== “ok”){ // no coockie
session.setItem(“prevPage”, wixLocation.url);
wixLocation.to(“www.askPassword.com”);
}
});

www.askPassword.com

local.setItem(“password”, “ok”);
let url = session.getItem(“prevPage”);
wixLocation.to(url);

Use a router:
https://www.wix.com/corvid/reference/wix-router.html

Tnx, I’m trying it now. But first - stupid question: after I add a page to the Router, where can I see its url? I used to find it at settings->SEO but at the Routers pages it is not there… I looked everywhere

And one more important thing: is there a way to get wix storage (coockies) from backend (Routers.js)?