Search code examples
javascriptmeteorflow-router

meteor - unexpected token error when using arrow notation


I'm implementing some routing groups, based on post I found which uses arrow notation.

I'm using the latest version of meteor and all top level dependencies are up to date too.

When I save my routes.js, I get an unexpected token error which fails on the arrow notation in the code. I'm missing something obvious I'm sure, any clues?

loggedIn = FlowRouter.group
  triggersEnter: [ ->
    unless Meteor.loggingIn() or Meteor.userId()
      route = FlowRouter.current()
      unless route.route.name is 'login'
        Session.set 'redirectAfterLogin', route.path
      FlowRouter.go ‘loginLayout’
  ]

Error:

While building for web.browser: imports/startup/client/routes.js:10:18: Unexpected token (10:18)


Solution

  • The tutorial is in coffeescript not js and you are loading it in a .js file which should be .coffee however if you have other js code in routes.js then you need to convert coffee to js. The snippet above would become:

    var loggedIn = FlowRouter.group({ 
        triggersEnter: [ function() { 
            var route; 
            if (!(Meteor.loggingIn() || Meteor.userId())) { 
                route = FlowRouter.current(); 
                if (route.route.name !== 'login') { 
                    Session.set('redirectAfterLogin', route.path); 
                } 
                return FlowRouter.go(‘loginLayout’); 
            } 
        }] 
    });