middleware_stack.js:31 Uncaught Error: Handler with name 'route' already exists. Iron router Meteor
Asked Answered
P

3

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?

Phthalein answered 16/3, 2016 at 9:37 Comment(1)
I have the same problem. Weirdly, I have this problem on Chrome 51 but not on Chrome 46.Borghese
J
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

Jugendstil answered 26/4, 2016 at 12:6 Comment(5)
Chrome 51 (stable as of late May 2016) is the first non-Canary release to be affected by this.Bipartite
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:[email protected] to fix this issue.Ecospecies
@Ecospecies 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.Jugendstil
@Jugendstil The version is 1.1.0.3Ecospecies
Perfect! It seems like Firefox is also following suite. This also fixed it for the latest Firefox as well as Chrome and Edge!Overpraise
B
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"
});
Borghese answered 29/3, 2016 at 5:26 Comment(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.Jugendstil
R
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.

Ramayana answered 16/3, 2016 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.