Uncaught TypeError: hook.apply is not a function on using onEnter in react-router

Uncaught TypeError: hook.apply is not a function on using onEnter in react-router

下面是代码片段:

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}
};

进入路径 /admin-area/admin-list 后,我从文件 TransitionUtils.js.

中得到标题中提到的错误

我不确定是什么导致了这个错误。有人可以帮忙吗?

这是 React Router 未能告诉您 onEnter 需要是一个函数(您目前正在将其包装在一个对象中)。

要解决此问题,只需将函数本身分配给 onEnter 属性(顺便说一句,您不需要将 onEnter 括在引号中):

  onEnter: requireAuth