mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 01:03:03 +08:00
chore(react): updating types for location state to fix type errors (#20207)
This commit is contained in:
@ -2,10 +2,10 @@ import { MemoryHistory } from 'history';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MemoryRouter, MemoryRouterProps, matchPath } from 'react-router';
|
import { MemoryRouter, MemoryRouterProps, matchPath } from 'react-router';
|
||||||
|
|
||||||
import { RouteManager } from './Router';
|
import { LocationState, RouteManager } from './Router';
|
||||||
|
|
||||||
interface IonReactMemoryRouterProps extends MemoryRouterProps {
|
interface IonReactMemoryRouterProps extends MemoryRouterProps {
|
||||||
history: MemoryHistory;
|
history: MemoryHistory<LocationState>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IonReactMemoryRouter extends React.Component<IonReactMemoryRouterProps> {
|
export class IonReactMemoryRouter extends React.Component<IonReactMemoryRouterProps> {
|
||||||
|
@ -14,12 +14,21 @@ import { RouteManagerContext, RouteManagerContextState } from './RouteManagerCon
|
|||||||
import { ViewItem } from './ViewItem';
|
import { ViewItem } from './ViewItem';
|
||||||
import { ViewStack, ViewStacks } from './ViewStacks';
|
import { ViewStack, ViewStacks } from './ViewStacks';
|
||||||
|
|
||||||
interface RouteManagerState extends RouteManagerContextState {
|
export interface LocationState {
|
||||||
location?: HistoryLocation;
|
direction?: RouterDirection;
|
||||||
action?: IonRouteAction;
|
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;
|
listenUnregisterCallback: UnregisterCallback | undefined;
|
||||||
activeIonPageId?: string;
|
activeIonPageId?: string;
|
||||||
currentIonRouteAction?: IonRouteAction;
|
currentIonRouteAction?: IonRouteAction;
|
||||||
@ -30,7 +39,7 @@ export class RouteManager extends React.Component<RouteComponentProps, RouteMana
|
|||||||
routerOutlets: { [key: string]: HTMLIonRouterOutletElement; } = {};
|
routerOutlets: { [key: string]: HTMLIonRouterOutletElement; } = {};
|
||||||
firstRender = true;
|
firstRender = true;
|
||||||
|
|
||||||
constructor(props: RouteComponentProps) {
|
constructor(props: RouteManagerProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.listenUnregisterCallback = this.props.history.listen(this.historyChange.bind(this));
|
this.listenUnregisterCallback = this.props.history.listen(this.historyChange.bind(this));
|
||||||
this.handleNavigate = this.handleNavigate.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;
|
const ionRouteAction = this.currentIonRouteAction === 'pop' ? 'pop' : action.toLowerCase() as IonRouteAction;
|
||||||
let direction = this.currentRouteDirection;
|
let direction = this.currentRouteDirection;
|
||||||
|
|
||||||
@ -115,7 +124,7 @@ export class RouteManager extends React.Component<RouteComponentProps, RouteMana
|
|||||||
this.currentIonRouteAction = undefined;
|
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 direction: RouterDirection | undefined = (location.state && location.state.direction) || 'forward';
|
||||||
let leavingView: ViewItem | undefined;
|
let leavingView: ViewItem | undefined;
|
||||||
const viewStackKeys = viewStacks.getKeys();
|
const viewStackKeys = viewStacks.getKeys();
|
||||||
|
Reference in New Issue
Block a user