chore(react): updating types for location state to fix type errors (#20207)

This commit is contained in:
Ely Lucas
2020-01-14 12:49:58 -07:00
committed by GitHub
parent 8732a10757
commit 28aa5eed94
2 changed files with 17 additions and 8 deletions

View File

@ -2,10 +2,10 @@ import { MemoryHistory } from 'history';
import React from 'react';
import { MemoryRouter, MemoryRouterProps, matchPath } from 'react-router';
import { RouteManager } from './Router';
import { LocationState, RouteManager } from './Router';
interface IonReactMemoryRouterProps extends MemoryRouterProps {
history: MemoryHistory;
history: MemoryHistory<LocationState>;
}
export class IonReactMemoryRouter extends React.Component<IonReactMemoryRouterProps> {

View File

@ -14,12 +14,21 @@ import { RouteManagerContext, RouteManagerContextState } from './RouteManagerCon
import { ViewItem } from './ViewItem';
import { ViewStack, ViewStacks } from './ViewStacks';
interface RouteManagerState extends RouteManagerContextState {
location?: HistoryLocation;
export interface LocationState {
direction?: RouterDirection;
action?: IonRouteAction;
}
export class RouteManager extends React.Component<RouteComponentProps, RouteManagerState> {
interface RouteManagerProps extends RouteComponentProps<{}, {}, LocationState> {
location: HistoryLocation<LocationState>;
}
interface RouteManagerState extends RouteManagerContextState {
location?: HistoryLocation<LocationState>;
action?: IonRouteAction;
}
export class RouteManager extends React.Component<RouteManagerProps, RouteManagerState> {
listenUnregisterCallback: UnregisterCallback | undefined;
activeIonPageId?: string;
currentIonRouteAction?: IonRouteAction;
@ -30,7 +39,7 @@ export class RouteManager extends React.Component<RouteComponentProps, RouteMana
routerOutlets: { [key: string]: HTMLIonRouterOutletElement; } = {};
firstRender = true;
constructor(props: RouteComponentProps) {
constructor(props: RouteManagerProps) {
super(props);
this.listenUnregisterCallback = this.props.history.listen(this.historyChange.bind(this));
this.handleNavigate = this.handleNavigate.bind(this);
@ -87,7 +96,7 @@ export class RouteManager extends React.Component<RouteComponentProps, RouteMana
}
}
historyChange(location: HistoryLocation, action: HistoryAction) {
historyChange(location: HistoryLocation<LocationState>, action: HistoryAction) {
const ionRouteAction = this.currentIonRouteAction === 'pop' ? 'pop' : action.toLowerCase() as IonRouteAction;
let direction = this.currentRouteDirection;
@ -115,7 +124,7 @@ export class RouteManager extends React.Component<RouteComponentProps, RouteMana
this.currentIonRouteAction = undefined;
}
setActiveView(location: HistoryLocation, action: IonRouteAction, viewStacks: ViewStacks) {
setActiveView(location: HistoryLocation<LocationState>, action: IonRouteAction, viewStacks: ViewStacks) {
let direction: RouterDirection | undefined = (location.state && location.state.direction) || 'forward';
let leavingView: ViewItem | undefined;
const viewStackKeys = viewStacks.getKeys();