为什么我使用React Router进行未定义而不是函数?

时间:2016-11-16 20:29:40

标签: javascript reactjs react-router react-dom

我正在使用React Router v4.0.0-alpha.3和create-react-app,如下所示:

// For react app
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Match, Miss } from 'react-router';

import './css/style.css';
// For electron app ~
import './ReactotronConfig'
import StorePicker from './components/StorePicker'
import App from './components/App'

class NotFound extends React.Component {
  render() {
    return (
      <div>Not Found.</div>
    )
  }
}

const Root = () => {
  return (
    <BrowserRouter>
      <div>
        <Match exactly pattern="/" component={StorePicker} />
        <Match pattern="/store/:storeId" component={App} />
        <Miss component={NotFound} />
      </div>
    </BrowserRouter>
  );
}


render(
  <Root />,
  document.querySelector('#main')
)

我收到了这些错误。

Render Method Errors

我发现在网上造成这种情况的唯一原因是我可能导入错误,但我是AFAIK。我非常确定我会忽略一些明显的东西。

App和Storepicker的代码:

import React from 'react'
import Header from './Header'
import Order from './Order'
import Inventory from './Inventory'

const App = ({...props}) => (
  <div className='catch-of-the-day'>
    <div className='menu'>
      <Header tagline="Fresh Seafood Market" />
    </div>
    <Order />
    <Inventory />
  </div>
)

export default App

-

import React, {Component} from 'react'

class StorePicker extends Component {
  render() {
    return (
      <form className='store-selector'>
        <h2>Please Enter A Store</h2>
        <input type='text' required placeholder='Store Name'/>
        <button type='submit'>Visit Store ☞</button>
      </form>
    )
  }
}

export default StorePicker

0 个答案:

没有答案