From b907726bbd527634b959a042aafdaede6a022554 Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Thu, 29 Jun 2023 10:20:14 -0400 Subject: [PATCH] chore: migrate IonReactRouter to react-router v6 --- .../src/ReactRouter/IonReactRouter.tsx | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/packages/react-router/src/ReactRouter/IonReactRouter.tsx b/packages/react-router/src/ReactRouter/IonReactRouter.tsx index 0bde559916..e34ece3c8b 100644 --- a/packages/react-router/src/ReactRouter/IonReactRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonReactRouter.tsx @@ -1,53 +1,14 @@ -import type { Action as HistoryAction, History, Location as HistoryLocation } from 'history'; -import { createBrowserHistory as createHistory } from 'history'; +import type { PropsWithChildren } from 'react'; import React from 'react'; -import type { BrowserRouterProps } from 'react-router-dom'; +import type { RouterProps } from 'react-router-dom'; import { Router } from 'react-router-dom'; import { IonRouter } from './IonRouter'; -interface IonReactRouterProps extends BrowserRouterProps { - history?: History; -} - -export class IonReactRouter extends React.Component { - historyListenHandler?: (location: HistoryLocation, action: HistoryAction) => void; - history: History; - - constructor(props: IonReactRouterProps) { - super(props); - const { history, ...rest } = props; - this.history = history || createHistory(rest); - this.history.listen(this.handleHistoryChange.bind(this)); - this.registerHistoryListener = this.registerHistoryListener.bind(this); - } - - /** - * history@4.x passes separate location and action - * params. history@5.x passes location and action - * together as a single object. - * TODO: If support for React Router <=5 is dropped - * this logic is no longer needed. We can just assume - * a single object with both location and action. - */ - handleHistoryChange(location: HistoryLocation, action: HistoryAction) { - const locationValue = (location as any).location || location; - const actionValue = (location as any).action || action; - if (this.historyListenHandler) { - this.historyListenHandler(locationValue, actionValue); - } - } - - registerHistoryListener(cb: (location: HistoryLocation, action: HistoryAction) => void) { - this.historyListenHandler = cb; - } - - render() { - const { children, ...props } = this.props; - return ( - - {children} - - ); - } +export function IonReactRouter({ children, ...props }: PropsWithChildren) { + return ( + + {children} + + ); }