Uncaught TypeError: hook.apply is not a function when using onEnter in a reaction router

The following is a snippet of code:

function requireAuth(nextState, transition, callback) {
  console.log('hey');

  callback();
}


export const AdminList = {
  'path': 'admin-area/admin-list',
  getComponent(location, cb) {
    require.ensure([], (require) => {
      cb(null, require('components/admin/admin-list/admin-list').default);
    }, 'admin-list');
  },
  'onEnter': {requireAuth}
};

When /admin-area/admin-listI enter the path, I get the error mentioned in the header from the TransitionUtils.js file .

I am not sure what causes this error. Can anybody help?

+4
source share
1 answer

This is a React Router without telling you what onEntershould be a function (you are currently wrapping it in an object).

To fix this, simply set the function itself to a property onEnter(btw, you don't need to wrap it onEnterin quotation marks):

  onEnter: requireAuth
+2
source

All Articles