我正在尝试将现有的反应项目转换为打字稿。除了 react-router 的 Navigation mixin(版本 0.13.3)之外,几乎所有东西都运行良好。我目前收到一条错误消息,指出“无法读取未定义的属性‘路由器’。”
我的主页代码目前如下所示:
/// <reference path="../typings/react/react.d.ts" />
/// <reference path="../typings/react-router/react-router.d.ts" />
import React = require('react');
import ReactRouter = require('react-router');
import Header = require('./common/header.tsx');
var Navigation = ReactRouter.Navigation;
class Home extends React.Component<{}, {}> {
static contextTypes: React.ValidationMap<any> = {
router: React.PropTypes.func.isRequired
};
render(): JSX.Element {
return (
<div>
<Header.Header MenuItems={[]}/>
<div className="jumbotron">
<h1>Utility</h1>
<p>Click on one of the options below to get started...</p>
<a className="btn btn-lg" onClick={() => Navigation.transitionTo('Route1')}>Route1</a>
<a className="btn btn-lg" onClick={() => Navigation.transitionTo('Route2')}>Route2</a>
</div>
</div>
);
}
}
export = Home;