Iron Rout noob question


Hi guys,

I am trying to create a very simple login/sign up system using Iron Route. When user logs in, I would like do direct him to my logged in template:

<template name="cards">
   {{#if currentUser}}
      Logged in
      <input type="button" class="logout" value="Logout">

Simple stuff.

My events template is:{
  'click .register' (event, template) {
  'submit form' (event, template) {
    var emailVar = $("#email").val();
    var passwordVar = $("#password").val();
    Meteor.loginWithPassword(emailVar, passwordVar, function(err) {
        if (err) {
          Session.set("showError", true);
        } else {
          Session.set("showError", false);

The failure is in “Route.go(cards)”. The error is:

Exception in delivering result of invoking ‘login’: ReferenceError: Route is not defined

What could the problem be? Is it the fact that I cannot call Route.go inside of a callback function? How can I fix that?

Thanks all


Yes! I got it. The issue was not using the Iron Route hooks. They are the ones that make this happen. So now I have this:

Router.route('/cards', {
  template: 'cards',
  onBeforeAction: function(){
        var currentUser = Meteor.userId();
        } else {

Router.route('/', {
    template: 'login',
    name: 'login',
    onBeforeAction: function(){
          var currentUser = Meteor.userId();
          } else {

works like a charm.

Question to you guys… Flow Route or Iron Route… should I go for any in specific or both great?


It’s advisable to start using flow router as iron router has been abandoned as far as I know.


Definitely FlowRouter.


yeah if you’re just getting started now (“noob question”) you should skip IronRouter. It’s considered legacy. Use FlowRouter (or React Router if you’re using React).


Thanks for the tips guys. Flow route it is theb


@fcaldas: Where did you see/read about iron router?

I am curious to know how/why new projects are being started with this package…


I took it from here:
It was well written and explained, so went for it.


Thanks, good to know!