【问题标题】:component undefined react-router组件未定义反应路由器
【发布时间】:2016-01-17 02:34:13
【问题描述】:

我运行了 react 0.13-router,它使用 router.create 但 1.0.3 它没有工作
我正在使用 router-react,如 this 示例中所示

但我有以下错误

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
{ [Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.] name: 'Invariant Violation', framesToPop: 1 }

这是向我显示 renderProps 的日志

{ routes: 
   [ { childRoutes: [Object] },
     { path: '/',
       component: [Function: BaseAdmin],
       indexRoute: [Object],
       childRoutes: [Object] },
     { component: [Function: Home] } ],
  params: {},
  location: 
   { pathname: '/',
     search: '',
     hash: '',
     state: null,
     action: 'POP',
     key: 'zljum4',
     query: {},
     '$searchBase': { search: '', searchBase: '' } },
  components: [ undefined, [Function: BaseAdmin], [Function: Home] ],
  history: 
   { listenBefore: [Function: listenBefore],
     listen: [Function: listen],
     transitionTo: [Function: transitionTo],
     push: [Function: push],
     replace: [Function: replace],
     go: [Function: go],
     goBack: [Function: goBack],
     goForward: [Function: goForward],
     createKey: [Function: createKey],
     createPath: [Function: createPath],
     createHref: [Function: createHref],
     createLocation: [Function: createLocation],
     setState: [Function: setState],
     registerTransitionHook: [Function: registerTransitionHook],
     unregisterTransitionHook: [Function: unregisterTransitionHook],
     pushState: [Function: pushState],
     replaceState: [Function: replaceState],
     isActive: [Function: isActive],
     match: [Function: match],
     listenBeforeLeavingRoute: [Function: listenBeforeLeavingRoute] } }

请举一些简单的例子来使用?

【问题讨论】:

    标签: express reactjs react-router react-dom


    【解决方案1】:

    看来你的问题来自这一行:

    components: [ undefined, [Function: BaseAdmin], [Function: Home] ],
    //            ^^^^^^^^^
    

    看起来它应该是一个组件。

    还请记住,React Router 在其主要版本中进行了重大的重大更改。因此,您可能需要仔细查看changelog 以获取升级提示。

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      相关资源
      最近更新 更多