connected-react-router
connected-react-router copied to clipboard
RouterState is missing `match` type
Connected React Router exports types for RouterState
which is great! However I don't see typings for match
. Would assume those could also be part of or be able to be imported into to reducer such as RouterState
is used below in examples:
https://github.com/supasate/connected-react-router/blob/master/examples/typescript/src/reducers/index.ts#L13
const rootReducer = (history: History) => combineReducers({
count: counterReducer,
router: connectRouter(history)
})
export interface State {
count: number
router: RouterState
}
Without which you can't really use this.props.match.params
for example in connected components as typings don't exist for match
. Is there a workaround here for those using TypeScript? Or am I missing a key part here? Thanks so much!
FWIW I ended up just using match
from react-router
and passed it in as an additional prop:
import { match } from 'react-router';
/**
* Additional props for connected React components.
* This prop is passed by default with `connect()`
* Note - `match` is provided by React Router and not connected in RouterState,
* so passed in below as additional prop
*/
export interface ConnectedReduxProps<A extends Action = AnyAction> {
dispatch: Dispatch<A>;
match: match<any>;
}
In use:
type AllProps = PropsFromState & PropsFromDispatch & ConnectedReduxProps;
class App extends React.Component<AllProps> { ... }
Would be curious though if folks would still consider this a bug as I would imagine there should still be typings exported from connected-react-router
?
Any news regarding this issue? What should be a proper way to inject match prop into a component using connected router?
So far I am using the solution mentioned by @bessfernandez .
This seems kind of important