diff --git a/packages/react-router/src/ReactRouter/IonReactHashRouter.tsx b/packages/react-router/src/ReactRouter/IonReactHashRouter.tsx index b2c210b9506..f5d68bb91fb 100644 --- a/packages/react-router/src/ReactRouter/IonReactHashRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonReactHashRouter.tsx @@ -1,15 +1,21 @@ -import { Action as HistoryAction, Location as HistoryLocation, createHashHistory as createHistory } from 'history'; +import { Action as HistoryAction, History, Location as HistoryLocation, createHashHistory as createHistory } from 'history'; import React from 'react'; import { BrowserRouterProps, Router } from 'react-router-dom'; import { IonRouter } from './IonRouter'; -export class IonReactHashRouter extends React.Component { - history = createHistory(this.props); +interface IonReactHashRouterProps extends BrowserRouterProps { + history?: History; +} + +export class IonReactHashRouter extends React.Component { + history: History; historyListenHandler?: ((location: HistoryLocation, action: HistoryAction) => void); - constructor(props: BrowserRouterProps) { + constructor(props: IonReactHashRouterProps) { super(props); + const { history, ...rest } = props; + this.history = history || createHistory(rest); this.history.listen(this.handleHistoryChange.bind(this)); this.registerHistoryListener = this.registerHistoryListener.bind(this); } diff --git a/packages/react-router/src/ReactRouter/IonReactRouter.tsx b/packages/react-router/src/ReactRouter/IonReactRouter.tsx index 7ec081d0239..e4079f32eaf 100644 --- a/packages/react-router/src/ReactRouter/IonReactRouter.tsx +++ b/packages/react-router/src/ReactRouter/IonReactRouter.tsx @@ -1,15 +1,22 @@ -import { Action as HistoryAction, Location as HistoryLocation, createBrowserHistory as createHistory } from 'history'; +import { Action as HistoryAction, History, Location as HistoryLocation, createBrowserHistory as createHistory } from 'history'; import React from 'react'; import { BrowserRouterProps, Router } from 'react-router-dom'; import { IonRouter } from './IonRouter'; -export class IonReactRouter extends React.Component { - history = createHistory(this.props); +interface IonReactRouterProps extends BrowserRouterProps { + history?: History; +} + +export class IonReactRouter extends React.Component { + historyListenHandler?: ((location: HistoryLocation, action: HistoryAction) => void); + history: History; - constructor(props: BrowserRouterProps) { + 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); } diff --git a/packages/react-router/test-app/cypress/integration/tab-context.js b/packages/react-router/test-app/cypress/integration/tab-context.js index c91d56c5f23..232eb58ca9f 100644 --- a/packages/react-router/test-app/cypress/integration/tab-context.js +++ b/packages/react-router/test-app/cypress/integration/tab-context.js @@ -1,6 +1,6 @@ const port = 3000; -describe.only('Tab Context', () => { +describe('Tab Context', () => { /* This spec tests the IonTabsContext API */ diff --git a/packages/react-router/test-app/src/App.tsx b/packages/react-router/test-app/src/App.tsx index f5db9cf4113..6190584fcce 100644 --- a/packages/react-router/test-app/src/App.tsx +++ b/packages/react-router/test-app/src/App.tsx @@ -38,7 +38,6 @@ const App: React.FC = () => { return ( - @@ -48,7 +47,6 @@ const App: React.FC = () => { - );