1Jerry
1Jerry

Reputation: 38

Meteor's Iron.Router adding an extra "/" to route names and not allowing home route

I am having a problem getting iron-router to correctly store and access routes. It appears that Iron.Router is adding an extra slash (/) before the route names, not ignoring case for template names, and not creating a default route.

I am adding Iron.Router to a simple testing app I have that I have split up for separate pages, but I cannot get any page to work as documented either with the map() or route() functions. I have spent hours trying options and searching and I seem to be the only one who ever had this problem. So I set up a minimum project to test. I created a new meteor project, removed the files, then copied basic.js and basic.html from https://github.com/EventedMind/iron-router/tree/devel/examples. All this example does is show three pages when you click between them. I then…

vagrant@precise32:/vagrant/test$ meteor add iron:router
vagrant@precise32:/vagrant/test$ meteor update
This project is already at Meteor 0.9.3.1, the latest release.
Your packages are at their latest compatible versions.
vagrant@precise32:/vagrant/test$ npm version
{ http_parser: '1.0',
  node: '0.10.32',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
  uv: '0.10.28',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1i',
  npm: '2.1.2' }
vagrant@precise32:/vagrant/test$ ls
basic.html  basic.js.
vagrant@precise32:/vagrant/test$ meteor

It started successfully, but threw a JS error on in Chrome (or FF). Exception from Tracker recompute function: Error: Couldn't find a template named "/" or "". Are you sure you defined it? Well yes, I did. Giving the route a blank name generates no error and no home page. So next I tried adding “/one” on the URL. I then get the JS error Error: Oh no! No route found for path: "/one". Next I changed the parameter in my route() call from “/one” to “one” and got this error: Error: Couldn't find a template named “one” or “one”. Are you sure you defined it? I then tried adding explicit code for route “one”: “function() { this.render(“Home”)} to reference the template “Home” using the same case. I got the exact same error message as without the explicit code. The only way I could get page one to display was to changed the name from “One” to “one” in the HTML. I couldn't get the default page to display at all.

When poking around (using Chrome’s console) in some internal variables, I found Router.routes, which has this highly suspicious content:

>Router.routes.forEach( function(v) {console.info("name = '%s', originalPath = '%s', re = '%s'",v.name,v.originalPath,v.re)})

2014-10-04 16:10:07.756 name = '/', originalPath = '//', re = '/^//?$/i'

2014-10-04 16:10:07.757 name = '/one', originalPath = '//one', re = '/^//one/?$/i'

2014-10-04 16:10:07.758 name = '/two', originalPath = '//two', re = '/^//two/?$/i'

(If I name the path "one", then the route will show 'one' as the name, and '/one' as the originalPath.

Details: This is a brand new folder with only these two files in it (and the hidden .meteor folder). The only package added was “iron:router”. I did a meteor update just before my last round of testing (one hour ago). I have set no environment variables. I have the latest version of Chrome & FireFox. I am using VirtualBox via Vagrant from Window 8 with 12G memory. Every other Meteor project I’ve done so far works, (well except for some trying to use jQuery).

If this was a bug in Iron:router, someone else would have noticed, but there are no more settings I can find anywhere that could be adding or subtracting the extra “/” in Iron-Router. Anyone have any ideas of what I need to look for for making a vanilla Iron-Router work with a vanilla Meteor project on my machine?

Upvotes: 1

Views: 588

Answers (1)

saimeunt
saimeunt

Reputation: 22696

You are really out of luck because your problem is very simple : you are running examples which are intended to work with the LATEST iron:[email protected], but your iron:router version is most likely 0.9.4.

Try this :

meteor remove iron:router
meteor add iron:[email protected]

If you want a little more insight, routes used to be declared with name first and path as an option, this is now the contrary.

0.9.4

Router.map(function(){
  this.route("home",{
    path:"/"
  });
});

1.0.0-pre3

Router.route("/",{
  name:"home"
});

Upvotes: 1

Related Questions