为什么在此React / Typescript应用程序中出现no export member错误?

时间:2018-09-22 21:16:55

标签: javascript reactjs typescript

enter image description here

router.tsx

import * as React from 'react';
import { Route, HashRouter, Switch } from 'react-router-dom';
import App from './App';
import { LoginContainer } from './containers';

export const AppRouter: React.StatelessComponent<{}> = () => {
  return (
    <HashRouter>
      <div className="container-fluid">
        <Route component={App} />
        <Switch>
          <Route exact path="/" component={LoginContainer} />
          <Route path="/login" component={LoginContainer} />
        </Switch>
      </div>
    </HashRouter>
  );
}

文件夹结构:

enter image description here

src / containers / index.ts

export * from './auth/LoginContainer';

最后是LoginContainer

import * as React from 'react';

class LoginContainer extends React.Component {
  public render() {
    return (
      <div>
        <header>
          <h1>This is the Login Container</h1>
        </header>
      </div>
    );
  }
}

export default LoginContainer;

1 个答案:

答案 0 :(得分:3)

您需要导出默认名称。

export { default as LoginContainer } from './auth/LoginContainer';

更多:http://jamesknelson.com/re-exporting-es6-modules/