【发布时间】:2018-04-08 02:22:40
【问题描述】:
我使用标准的 VisualStudio 2017 ASP.NET Core 2.0 React 模板。
我有来自模板的课程Home:
import { RouteComponentProps } from 'react-router';
export class Home extends React.Component<RouteComponentProps<{}>, {}> {
public render() {
return <div>
<h1>Hello, world!</h1>
</div>;
}
}
我需要创建routesData 数组并将Home 之类的组件绑定到“布局”路由。这是我的尝试代码:
interface RouteDataItem {
path: string;
exact: boolean;
main: () => Element;
}
export const routesData = [
{
path: '/',
exact: true,
main: () => <Home />
},
{
path: '/counter',
main: () => <Counter />
},
{
path: '/fetchdata',
main: () => <FetchData />
}
]
export const routes = <Layout>
{routesData.map((route, index) => {
return <Route exact={route.exact} key={index} path={route.path} component={route.main} />;
}}
</Layout>;
我该怎么做?
VisualStudio 显示错误Property "match" is absent in type "{}"
在这条线上
main: () => <Home />
<Home /> 是红色下划线。
【问题讨论】:
标签: reactjs typescript react-router