React Router试图将auth服务注入auth组件

时间:2017-03-26 17:03:08

标签: reactjs react-router

以下代码有效但不允许我通过路由将auth对象传递给authService。

    const routes = {

      path: '/',
      indexRoute: { onEnter: (nextState, replace) => replace('/home') } ,
      childRoutes: [
        {
        onEnter: requireAuth,
        childRoutes: [
          require('./routes/home').default,
        ]
        },
          require('./routes/auth').default, 
      ]
    };


    ReactDOM.render((
      <Provider store={store}>
        <Router
          history={history}
          routes={routes}
        />
      </Provider>
    ), document.getElementById('smartadmin-root'));

但是,下面的标准方法不会显示我的登录表单。

  ReactDOM.render((
  <Provider store={store}>
   <Router>
      <Route path="/" component={App}>
        <indexRoute onEnter={(nextState, replace) => replace('/home')} />
        <Route component={Home} onEnter={requireAuth}/>
        </Route>
          <Route path="login" component={Login}/>
    </Router>
  </Provider>
), document.getElementById('smartadmin-root'));

我错过了什么?

0 个答案:

没有答案