Strange iron:router behavior (params empty)

Hey there,
just look at this code - maybe you can explain why things work or not.
The short version is this:
Running Router.current().params logs an empty array [] to the console, while running Router.current().params._id logs the correct id. I just don’t think this is even possible :smile: Strange.

Here are some more examples, all of these functions are template helpers:

// 1. Doesn't work
pdf: function () {
  var params = Router.current().params;
  
  // Console Output:
  // []    
  console.log(params);
}


// 2. Works
pdf: function () {
  var id = Router.current().params._id;
  var n = Router.current().params.n;
  
  // Console Output:
  // C5hshvNHhddjhnvWq 0
  console.log(params, n);
}


// 3. Doesn't work
pdf: function () {
  var id = Router.current().params._id;
  var n = Router.current().params.n;
  
  var pdf = PDFs.findOne({
    patientId: id,
    quote: n
  });
    
  // Console Output:
  // undefined
  console.log(pdf)
}


// 4. Works
pdf: function () {

  // Values come from example 2
  var pdf = PDFs.findOne({
    patientId: 'C5hshvNHhddjhnvWq',
    quote: 0
  });
  
  // Console Output
  // > Object
  console.log(pdf);
}

This just doesn’t seem to make any sense. I basically want to get example 3 running, and I’ve never had such a problem before (or didn’t notice). Any idea why this might happen?

Silly question but have to ask: what are your routes and do you have the correct URLs in each example? In your third example, what happens when you try logging the values of id and n as well? Are they defined? Maybe I’m missing something obvious but it’s hard to say without seeing more.

Also in your first example, should it be console.log(id, n)?

@nkrisc, thanks for your response! I actually figured it out.
Using console.log doesn’t work, console.dir does. And my code didn’t work, because I stored a Number in the database, but the parameter was a string. My fault :slight_smile: