feat(react): React Router Enhancements (#21693)

This commit is contained in:
Ely Lucas
2020-07-07 11:02:05 -06:00
committed by GitHub
parent a0735b97bf
commit c171ccbd37
245 changed files with 26870 additions and 1124 deletions

View File

@ -1,28 +1,52 @@
import { RouterDirection } from '@ionic/core';
import { AnimationBuilder, RouterDirection } from '@ionic/core';
import React from 'react';
import { RouteInfo } from '../models';
export interface NavContextState {
getIonRoute: () => any;
getIonRedirect: () => any;
getPageManager: () => any;
getStackManager: () => any;
goBack: (defaultHref?: string) => void;
navigate: (path: string, direction?: RouterDirection | 'none', ionRouteAction?: 'push' | 'replace' | 'pop') => void;
goBack: (route?: string | RouteInfo, animationBuilder?: AnimationBuilder) => void;
navigate: (path: string, direction?: RouterDirection | 'none', ionRouteAction?: 'push' | 'replace' | 'pop', animationBuilder?: AnimationBuilder, options?: any, tab?: string) => void;
hasIonicRouter: () => boolean;
registerIonPage: (page: HTMLElement) => void;
currentPath: string | undefined;
routeInfo?: RouteInfo;
setCurrentTab: (tab: string, routeInfo: RouteInfo) => void;
changeTab: (tab: string, path: string, routeOptions?: any) => void;
resetTab: (tab: string, originalHref: string, originalRouteOptions?: any) => void;
}
export const NavContext = /*@__PURE__*/React.createContext<NavContextState>({
getIonRedirect: () => undefined,
getIonRoute: () => undefined,
getPageManager: () => undefined,
getStackManager: () => undefined,
goBack: (defaultHref?: string) => {
if (defaultHref !== undefined) {
window.location.pathname = defaultHref;
} else {
window.history.back();
goBack: (route?: string | RouteInfo) => {
if (typeof window !== 'undefined') {
if (typeof (route) === 'string') {
window.location.pathname = route;
} else {
window.history.back();
}
}
},
navigate: (path: string) => {
if (typeof window !== 'undefined') {
window.location.pathname = path;
}
},
navigate: (path: string) => { window.location.pathname = path; },
hasIonicRouter: () => false,
registerIonPage: () => undefined,
currentPath: undefined
routeInfo: undefined,
setCurrentTab: () => undefined,
changeTab: (_tab: string, path: string) => {
if (typeof window !== 'undefined') {
window.location.pathname = path;
}
},
resetTab: (_tab: string, path: string) => {
if (typeof window !== 'undefined') {
window.location.pathname = path;
}
}
});