为什么我不能在index.js中使用导出的路由

时间:2018-06-23 16:34:52

标签: javascript reactjs

我收到一个错误。 React.createElement:类型无效-预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义

我正在尝试使用Index.js中导入的riutes

    import React from 'react';
import ReactDom from 'react-dom';
import routes from './routes.js';
import { HashRouter as Router, Route, IndexRoute } from 'react-router-dom'; 

const renderApp = (appRoutes) => {
    ReactDom.render(appRoutes, document.getElementById('app'));
};

renderApp( routes() );  

我从route.js导出此路由

import React from 'react';
import { AppContainer } from 'react-hot-loader';
import { BrowserRouter as Router, Route, browserHistory, IndexRoute } from 'react-router-dom';
import App from './components/App';

const routes = () => (

    <AppContainer>
            <Router history={browserHistory} component={App}>


            </Router>

    </AppContainer>

);

export default routes;

1 个答案:

答案 0 :(得分:0)

您可能想致电routes

renderApp( routes() );