Router Redirection

Hi everyone !!!
This question, I searched for every where, but didn’t get any proper answer…

Here’s it is →
I have a database called “Members” which stores ‘userId’ ‘name’ and ‘email’
So, what I am trying to do is when a user enters my home page, if he/she is logged in then they should be redirected to another dynamic page… If not logged-in then nothing happens…

I found the APIs not very understandable…:sweat_smile::sweat_smile::sweat_smile:
So, if anyone can provide any examples or clue, it will be very useful !!! (Not Wix.Location.to() )

Thanks !!!

You can’t use wix-routers for the homepage.
You’ll have to use wixLocation.to()

Thanks J.D
I was just asking if one user enters one page of my site, if he/she is logged-in then they should be redirected to a dynamic page otherwise, nothing !

Biggest example →
When I type wix.com/ if I am logged-in then they redirect me to My Sites page.
If not logged-in then to the Wix page

@ajithkrr as I said, it is possible for every page except the homepage.

@jonatandor35 Thanks for letting me know!
After you commented about this I just created a new page…
So, can you help me here → when the user is on this page if she/he is logged in then they should be redirected to a dynamic page otherwise to this page itself…

@ajithkrr You should create a router page:
(where you add a new page, there’s also an option to create a router page and you should select it (it can’t be a name of an already-exist static page).
Then in the routers.js file (on the back end), you should make the redirect:

//   backend/routers.js
import {ok, redirect} from 'wix-router';
import wixUsersBackend from 'wix-users-backend';
export function pagename_Router(request) {
const user = wixUsersBackend.currentUser;
const isLoggedIn = user.loggedIn; 
if(!isLoggedIn) {return ok("pagename"); }
  return redirect('/destination-page-name/' + user.id );
}

@jonatandor35 Perfectly worked…
Thanks for your guidance…

Hi J.D !!!
I am having a doubt →
When the router page is opened the title of the page is
home | Mysite 3
Can I change this to something else ???

I’m not sure if you’re talking about the router page itself or the redirection page.
If it’s the latter, you can go to the page settings > SEO and change it from there.
You should also have a look at:
https://www.wix.com/corvid/reference/wix-router/sitemap

Hi J. D. !!!
I don’t why this is coming →

I think I should use the siteMap function…
But clearly I didn’t found out how to …
@yisrael-wix