【问题标题】:Why I can not use exported routes in index.js为什么我不能在 index.js 中使用导出的路由
【发布时间】:2018-06-23 16:34:52
【问题描述】:

我收到一个错误。 React.createElement: type is invalid -- 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但是得到:未定义

我正在尝试在 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() );  

我从 routes.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;

【问题讨论】:

  • 我们真的需要看到routes.js 才能正确诊断发生了什么
  • 楼上可以看到

标签: javascript reactjs


【解决方案1】:

你可能想打电话给routes

renderApp( routes() );  

【讨论】:

    猜你喜欢
    • 2021-02-28
    • 2019-12-01
    • 2020-04-22
    • 2021-04-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多