Hi, I have coded my router on the back end of my site. It is for redirecting visitors weather they are a desktop viewer or mobile, and each have a separate home page.
I currently have a landing page handling this similar task, with hidden buttons- but I created the router hoping this will handle the redirect more seamlessly, and I can remove the landing page. Better for SEO purposes as well.
Now that I have the router, what do I need to change on my pages end, for it to function properly? Should I have my desktop home page set at the site “home” since my code redirects mobile visitors? Do I need to “add pages” under the router page in my menu? Can’t seem to find articles on this process.
See my router code below, might help give some context. (Sample URL) Currently, my landing page is the “home” page.
In order to present different pages you need to set one of them as your router page, because the router page is the one that get the data from the backend router function.
You can add a getRouterData() function in the onReady() function of your page in order to determine if the user is going to see the current page or open a new page (using wixLocation.to() function).
Refer to your code, what you need to return from the router function is a value that let you now if the user is on mobile or desktop (like boolean value). After that, add the condition in the onReady() function and navigate the user.
Hi Sapir, thanks for your response I really appreciate it. I have a couple of questions:
1: How do I set my page as the router page? “Add page to router” in the pages menu?
2: To be clear, the code I have above what I should use and there needs to be an additional wixLocation.to() function on the page I assign to the router?
3: I am unclear what you mean by the last thought “Refer to your code, what you need to return from the router function is a value that let you now if the user is on mobile or desktop (like boolean value). After that, add the condition in the onReady() function and navigate the user.”