简体   繁体   中英

module.exports not working ES6

I am using the tutorial found here:

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

However when copying:

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 is highlighting the brackets and using:

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

But routes throws the error

Default export is not declared in imported module

The page just loads blank with no react code. Why can I not export the module as shown in the tutorial code?

The rest of my code is ES6

rselvaganesh is technically correct, however in this case it should be:

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>
)

with no name - which is what was confusing me

This issue was posted here

Changing in AppActions

module.exports = alt.createActions(AppActions);

To:

export default alt.createActions(AppActions);

Makes WebStorm happier and doesn't seem to break anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM