我最新的代碼
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { BrowserRouter as Router, Route, Switch, RouteComponentProps } from 'react-router-dom';
import { Provider } from 'react-redux';
import Counter from './containers/Container';
import store from './stores/store';
import NotFound from './components/NotFound';
class PostsIndex extends React.Component<RouteComponentProps<any>, {}> {
render() {
return (
<div>
Index page
</div>
)
}
}
ReactDOM.render(
<Provider store={store}>
<Router>
<div>
<Switch>
<Route exact path="/" component={PostsIndex} />
<Route exact path="/counter" component={Counter} />
<Route component={NotFound} />
</Switch>
</div>
</Router>
</Provider>
, document.getElementById('app')
);
容器/組件
export default connect(
(state: ReduxState) => ({value: state.counter}),
(dispatch: Dispatch<ReduxAction>, ownProps: RouteComponentProps<{myParams: string}>) => {
return {actions: new ActionDispatcher(dispatch)}
}
)(Counter);
錯誤消息
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(46,29): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(56,31): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(74,28): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(79,29): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(87,35): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in /workspace/react-router-typescript/node_modules/@types/react-router/index.d.ts
(92,29): error TS2314: Generic type 'Component<P, S>' requires 2 type argument(s).
ERROR in ./src/Index.tsx
(24,10): error TS2604: JSX element type 'Switch' does not have any construct or call signatures.
ERROR in ./src/Index.tsx
(25,12): error TS2604: JSX element type 'Route' does not have any construct or call signatures.
ERROR in ./src/Index.tsx
(26,12): error TS2604: JSX element type 'Route' does not have any construct or call signatures.
ERROR in ./src/Index.tsx
(27,12): error TS2604: JSX element type 'Route' does not have any construct or call signatures.
有可能是在一個錯誤的反應路由器...
構建失敗,但成功頁面轉換和呈現...
這是什麼版本的反應路由器? – Li357
「react-router」:「^ 4.1.1」, 「@ types/react-router」:「^ 4.0.12」, – hohihohi