18

My code was working fine until last night and suddenly I am getting this error and routes are not working at all.

middleware_stack.js:31Uncaught Error: Handler with name 'route' already exists.

for simple routes like this:

Router.route('/admin/dashboard', {
   template:"adminDashboard"
});

Router.route('/admin/create/table', {
  template:"create_table"
});

I cannot figure out the error, I have checked all the routes. Have anyone else faced this error?

Bipin Bhandari
  • 2,656
  • 20
  • 38

3 Answers3

61

This is a known issue. The problem occurs with recent versions of Google Chrome and Microsoft Edge (edit: also Firefox now).

It has been fixed by a recent iron router update, it should be fixed by meteor update iron:middleware-stack.

Edit: If the middleware-stack package rolls back when you restart the server, check @bigsan's comment

Julien
  • 8,970
  • 9
  • 60
  • 86
  • 2
    Chrome 51 (stable as of late May 2016) is the first non-Canary release to be affected by this. – market Jun 01 '16 at 03:50
  • 7
    Because `iron:middleware-stack` is not explicitly listed in my `.meteor/packages` file, it will be rolled back to old version on meteor server restarting. I have to run `meteor add iron:middleware-stack@1.1.0` to fix this issue. – bigsan Jun 06 '16 at 02:11
  • @bigsan Out of curiosity, which version of Meteor do you use? I'll edit the answer if I can figure out why you have this problem. – Julien Jun 06 '16 at 12:59
  • 1
    @Julien The version is 1.1.0.3 – bigsan Jun 06 '16 at 13:47
  • Perfect! It seems like Firefox is also following suite. This also fixed it for the latest Firefox as well as Chrome and Edge! – TechnoTim Jun 17 '16 at 03:39
4

Edit: this issue was fixed in iron:middleware-stack 1.1.0 .

I have the same problem. Weirdly, I have this problem on Chrome 51 but not on Chrome 46. I guess this has to do with updates in the javascript engine, and I'll post here if I figure out what exactly.

In the meantime, the workaround I used was to explicitly add names to the routes. It doesn't matter what they are, they just have to be declared, otherwise iron-router think the name of the route is "route." So your code would become:

Router.route('/admin/dashboard', {
   name: "Boaty_McBoatface",
   template:"adminDashboard"
});

Router.route('/admin/create/table', {
   name: "Guacamole",
   template:"create_table"
});
foobarbecue
  • 6,114
  • 3
  • 25
  • 50
  • 1
    Upvoted too quickly, my routes have names, but I have the problem anyways. Posted another answer below, for those for whom it doesn't work either. – Julien Apr 26 '16 at 12:08
0

First, have a look here and see when this error is thrown. So, actually I have not faced that error but I've read about it. Further have a look at the official guide and post. I see that you are trying to create a subdirectory to your route /admin. Usually, I do this by using this.render() function. Concerning the layout I use this.layout() so I think that if you use these functions and remove template:"adminDashboard". It will work.

Community
  • 1
  • 1
StefanL19
  • 1,418
  • 1
  • 12
  • 26