mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
feat(react): React Router Enhancements (#21693)
This commit is contained in:
24
packages/react/src/components/IonRouterContext.tsx
Normal file
24
packages/react/src/components/IonRouterContext.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
import { AnimationBuilder } from '@ionic/core';
|
||||
import React, { useContext } from 'react';
|
||||
|
||||
import { RouteAction, RouterDirection, RouterOptions } from '../models';
|
||||
import { RouteInfo } from '../models/RouteInfo';
|
||||
|
||||
export interface IonRouterContextState {
|
||||
routeInfo: RouteInfo;
|
||||
push: (pathname: string, routerDirection?: RouterDirection, routeAction?: RouteAction, routerOptions?: RouterOptions, animationBuilder?: AnimationBuilder) => void;
|
||||
back: (animationBuilder?: AnimationBuilder) => void;
|
||||
canGoBack: () => boolean;
|
||||
}
|
||||
|
||||
export const IonRouterContext = React.createContext<IonRouterContextState>({
|
||||
routeInfo: undefined as any,
|
||||
push: () => { throw new Error('An Ionic Router is required for IonRouterContext'); },
|
||||
back: () => { throw new Error('An Ionic Router is required for IonRouterContext'); },
|
||||
canGoBack: () => { throw new Error('An Ionic Router is required for IonRouterContext'); }
|
||||
});
|
||||
|
||||
export function useIonRouter() {
|
||||
const context = useContext(IonRouterContext);
|
||||
return context;
|
||||
}
|
Reference in New Issue
Block a user