react-Router-v4上的React.CreateElement问题,而不是v4-alpha4

时间:2017-03-13 14:49:23

标签: reactjs react-router

我正在试图弄清楚为什么某个特定功能正在使用反映路由器的alpha版本而不是当前的v4版本

index.js

import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Match } from 'react-router';

import NotFound from './components/NotFound';

const Root = () => {
  return (
    <BrowserRouter>
      <div>
        <Match exactly pattern="/" component={NotFound} />
      </div>
    </BrowserRouter>
  )
}

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

的package.json

{
  "name": "rbm-dashboard",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "material-ui": "^0.17.0",
    "react": "^15.4.2",
    "react-tap-event-plugin": "^2.0.1",
    "react-dom": "^15.4.2"
  },
  "devDependencies": {
    "react-router": "4.0.0-alpha.4",
    "react-scripts": "0.9.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

NotFound.js

import React from 'react';

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

export default NotFound;

当我将react-router版本从4.0.0-alpha.4切换到^ 4.0.0时,我收到以下错误

enter image description here

我没有使用alpha版本的问题,但我想弄清楚问题是什么,所以我可以从中学习。如果需要,我可以将代码推送到github,如果有人想在本地查看它。

谢谢

1 个答案:

答案 0 :(得分:2)

因为Match不再是一件事了。将Match pattern更改为Route path,您应该感觉良好。另外,从react-router-dom而不是react-router导入所有内容。