【发布时间】:2017-12-05 15:10:33
【问题描述】:
我正在将代码从 javascript 替换为 typescript。但是,构建失败。
- JSX element type 'Router' does not have any construct or call signatures.
- JSX element type 'Switch' does not have any construct or call signatures.
- JSX element type 'Route' does not have any construct or call signatures.
如何解决这个错误?
代码错误
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Router, Switch, Route } from 'react-router';
import { Provider } from 'react-redux';
import createBrowserHistory from 'history/createBrowserHistory';
import Counter from './containers/Container';
import store from './stores/store';
import NotFound from './components/NotFound';
const history = createBrowserHistory();
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Switch>
<Route exact path="/counter" component={Counter} />
<Route path="/counter/:id" component={Counter} />
<Route component={NotFound}/>
</Switch>
</Router>
</Provider>
, document.getElementById('app')
);
当我使用 import { Route } from 'react-router-dom'; 时发生同样的错误。
【问题讨论】:
-
这是什么版本的react路由器?
-
"react-router": "^4.1.1", "@types/react-router": "^4.0.12",
标签: reactjs react-router react-redux react-router-dom