Mobile only routes with iron router?

Is this something that is possible? I’m relatively new to meteor, and am working on a project with it. Ideally, I’d like to have templates that are viewable only on certain screen sizes (for mobile), rather than just doing a responsive layout with media queries. I’d like to do this, because I have certain portions of the site that I am building that I want to be available only to mobile users.

Off the top of my head, I’ve come up with some hacky solutions - like having two different navs (with their display controlled via media queries) and thus having a set of templates for mobile and non-mobile. But this doesn’t really seem elegant, and I’m wondering if there’s a better way…

I haven’t done this myself… not sure if it will work, but this is what I would try to begin with.

Couldn’t you have all your client side routes, behind a conditional variable based on the detected client? You could use a session variable with the default value being the detected value. Users could override that if they wanted to see the full-site.

So have something like in your client side (not lib, or shared, otherwise will fail on the Session.get()), router.js file:

if (Session.get('ui-mobile')) {
  ... mobile routes...
  ... non mobile routes...
... global routes...
1 Like

@cstrat works like a charm