0

I am using iron:router@1.0.0-pre3 with meteor 9.3.1.

Template code:

<head>
  <title>ironman</title>
</head>

<body>
</body>

<template name="hello">
  <button>Click Me</button>
  <p>You've pressed the button {{counter}} times.</p>
</template>

Javascript code:

if (Meteor.isClient) {
    // counter starts at 0
    Session.setDefault("counter", 0);

    Template.hello.helpers({
        counter: function() {
            return Session.get("counter");
        }
    });

    Template.hello.events({
        'click button': function() {
            // increment the counter when button is clicked
            Session.set("counter", Session.get("counter") + 1);
        }
    });


    Router.route('/', function() {
        this.render('hello');
    });

}

The route defined above doesn't work. However, if I place the route definition outside if (Meteor.isClient) { it starts working.

Is this by design? Please advise.

Anish Singh
  • 881
  • 1
  • 13
  • 33

1 Answers1

0

This is by design.

IronRouter allows you to choose where routes should be apply : client or server. By default all routes are attached to client side, but you can choose to apply route to server side:

Router.route('/item', function () {
  var req = this.request;
  var res = this.response;
  res.end('hello from the server\n');
}, {where: 'server'});
Kuba Wyrobek
  • 5,273
  • 1
  • 24
  • 26