首页 文章

TypeScript,react-router和jsx:JSX元素类型'Route'没有任何构造或调用签名

提问于
浏览
2

在尝试使用TypeScript进行此演练React Integrating Routing to Material UI’s Left Nav (or Other Components)时获取 JSX element type 'Route' does not have any construct or call signatures .

我的代码:

const Routes = (
  <Route path="/" handler={Main}>
    <IndexRoute handler={ConnectionModule} />
  </Route>
);

导致TypeScript编译器使用上述错误消息对Route和IndexRount导入进行投诉 .

这是我的import语句(包括我自己的es模块) . 注意从 react-router 向中间导入 .

import { AppBar, Drawer, FontIcon, List, ListItem, MakeSelectable, TouchTapEvent } from 'material-ui';

import { deepOrange500 } from 'material-ui/styles/colors';
import { getMuiTheme, MuiThemeProvider } from 'material-ui/styles';

import * as React from 'react';
import { Component } from 'react';

import Router from 'react-router';
import { Route, IndexRoute, Redirect, Link } from 'react-router';


import MainState from './MainState';
import ConsoleModule from './ConsoleModule';

import ConnectionModule, { ConnectionModuleState } from './containers/ConnectionModule';

我正在使用这些版本的relavant npm包(来自package.json)

"material-ui": "^0.15.3",
"react": "^15.3.0",
"react-dom": "^15.3.0",
"react-router": "^2.6.1",
"react-tap-event-plugin": "^1.0.0",
"@types/material-ui": "^0.15.31",
"@types/node": "^6.0.32",
"@types/react": "^0.14.29",
"@types/react-dom": "^0.14.14",
"@types/react-router": "^2.0.30",
"typescript": "^2.1.0-dev.20160808",

相关链接:

1 回答

  • 0

    问题出在react-router定义文件中,你需要编辑它:为名为“React”的新命名空间更改名为“_React”的旧全局命名空间 .

    这只发生在使用npm类型安装时 .

相关问题