Search code examples
meteorroutesiron-router

Meteor useraccounts routes and route priority: how to ensure static routes are hit first?


I am using meteor useraccounts along with iron-router but my guess is this would apply the same to flow-router.

With Meteor useraccounts you configure/add routes like signIn, forgotPWD, etc... via code like:

AccountsTemplates.configureRoute('signIn', {
    name: 'signin',
    path: '/login',
    template: 'myLogin',
    layoutTemplate: 'myLayout',
    redirect: '/user-profile',
});

This is all fine and dandy except I also want to allow for a root parameterized route like:

Router.route '/:rootParam',
  name: 'rootParam'
  controller: share.WikiController
  onBeforeAction: ->
    rootParam = @params.rootParam
    if rootParam in share.staticRoutes
      Router.go(rootParam)  
    else
      @next()

So if the user goes to a route with an item id it works but if they go to a static useraccounts route like /login things also work.

I find its always hitting the parameter route and the static routes never work.


Solution

  • You can't do a Router.go() in onBeforeAction. You can render the route however. You might also have to change the layoutTemplate if your named routes use different layouts.