iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 412 forks source link

Failed on IE with blank page #1270

Open vuhpham opened 9 years ago

vuhpham commented 9 years ago

Hi forks, I got a blank page in IE11 with an error in console: Exception in callback of async function: Error: Handler with name 'hookWithOptions' already exists. capture Demo site of telescope got the same problem. Any idea about it?

tomwasd commented 9 years ago

I've narrowed it down, in my case, to it being due to multiple Router.onBeforeActions

For example:

Router.onBeforeAction(requireLogin, {name: 'requireLogin', only: ['dealEdit',     'userDashboard','userSettings', 'userNotifications']});
Router.onBeforeAction(requireAdmin, {name: 'requireAdmin', only: ['admin']});

Will cause the error. Removing one of the Router.onBeforeActions seems to fix it.

I had a look to see if I could solve the issue but I don't have the time at the mo to get my head around how everything fits together.

As a bandaid fix, you can move the onBeforeAction into each of the routes and it doesn't seem to cause an issue e.g.

this.route('userNotifications', {
  path: '/notifications',
  onBeforeAction: requireLogin
});
spacemunkay commented 8 years ago

+1 to tomwasd's solution. Thanks!

spacemunkay commented 8 years ago

If you were using a onBeforeAction for the 'dataNotFound' plugin, you can change it from:

Router.onBeforeAction('dataNotFound', {only: ['myRoute1', 'myRoute2']});

to

Router.plugin('dataNotFound', {
  notFoundTemplate: 'NotFound',
  //except: ['server.route']
   only: ['myRoute1', 'myRoute2']
});

EDIT: Welp, I thought that helped. Getting the error again, so perhaps not.