module.exports不工作ES6

时间:2017-03-07 13:39:07

标签: javascript reactjs

我正在使用此处的教程:

https://github.com/reactjs/react-router-tutorial/blob/master/lessons/14-whats-next/modules/routes.js

但是在复制时:

module.exports = (
  <Route path="/" component={App}>
    <IndexRoute component={Home}/>
    <Route path="/repos" component={Repos}>
      <Route path="/repos/:userName/:repoName" component={Repo}/>
    </Route>
    <Route path="/about" component={About}/>
  </Route>
)

Webstorm突出显示括号并使用:

import React from 'react'
import { Router, browserHistory } from 'react-router'
import routes from './routes'

路由会引发错误

Default export is not declared in imported module

页面只加载空白而没有反应代码。为什么我不能导出模块,如教程代码所示?

我的其余代码是ES6

2 个答案:

答案 0 :(得分:2)

rselvaganesh在技术上是正确的,但在这种情况下它应该是:

export default (
  <Route path="/" component={App}>
    <IndexRoute component={Home}/>
    <Route path="/repos" component={Repos}>
      <Route path="/repos/:userName/:repoName" component={Repo}/>
    </Route>
    <Route path="/about" component={About}/>
  </Route>
)

没有名字 - 这让我感到困惑

答案 1 :(得分:1)

此问题已发布here

更改AppActions

module.exports = alt.createActions(AppActions);

要:

export default alt.createActions(AppActions);

让WebStorm更快乐,似乎没有破坏任何东西。

相关问题