FlowRouter routing - dependent on Role and Auth

I am still learning flowrouter and am working on a project that uses it. I want to change the behavior of the root route “/” if a user has logged in.

I see lots of examples where within a template context one shows or hides content - but I am wondering if there’s a good pattern for (re)setting the route itself?

Eg, in: router.jsx

if (Meteor.userId()) {
  FlowRouter.route('/', {name: 'home', action: render(C.DashProperties, C.MainLayout)});
} else { // non-auth shows default landing 
  FlowRouter.route('/', {name: 'home', action: render(C.Home, C.NoHeaderLayout)});

It feels like there must be some way like this. Does anyone here have experience altering the route itself based on auth and or role? Or is it indeed best to just conditionally render diff stuff in the template (yuck)?

1 Like

Yes, that’s the right way to do it.

This is because the URL is not the main entry point in a client-rendered app like it is in a server side app like Rails. It’s natural then to centralize all of your data loading needs around the UI components, and not routes.


Thanks for the answer @sashko. Will approach that way then.

1 Like