Force site to load in Mobile mode

Is there a way to force the site to load as Mobile site?
I’m trying to find a workaround for Tablets. They tend to request the desktop site which does not fit.

Since we have a way to identify that the browser is a tablet, if we could “redirect” the site to the mobile version, this could be a solution.

I’m facing the same issue with you, but no clues what to do. Even with the corvid codes

wix-Location

might redirect to somewhere else, but not mobile site.
Considering switch platform.

You can use a router and do something like this:

import { redirect } from 'wix-router';

export function myRouter_Router(request) {
    if (some condition) {
    return redirect('https://mywebsite.com/?showmobileview=true', '301');
    }
}

Have you ever actually tried doing this? Once you add the line

import wixWindow from 'wix-window';

into your routers.js file it causes a 500 timeout error to any prefix pages. The Corvid Reference manual itself states “the APIs in wix window can only be used in front end code”. That means you can’t determine the form factor before loading the page (you’d have to wait until onReady). Or am I missing something?

@aquacruise You’re right, that code won’t work. I’ll update it for posterity so no one wastes their time with it.

I’ll also mention, making mobile site load on Tablet is not a good solution. Better to optimize your site, because it’s just going to look plain odd.

Adding following code to your pages should work.

import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
  if (wixWindow.formFactor !== 'Desktop') {
    wixLocation.to('/my_page?showmobileview=true');
  }
}

replace “my_page” with name of your page. You are effectively reloading the current page with query ?showmobileview=true added to it.

Not sure if a more elegant solution is made available by Wix, but I’ve used this work around on my site.