From 41a626080fb355d005d40815f44f59484ea68b75 Mon Sep 17 00:00:00 2001 From: Ely Lucas Date: Tue, 14 May 2019 14:08:48 -0600 Subject: [PATCH] fix(react): defaultHref fixes (#18278) * fix(react): making children prop optional on overlay components * fix(react): passing in defaultHref so it can be used if there is no prev view --- react/src/components/createControllerComponent.tsx | 4 ++-- react/src/components/createOverlayComponent.tsx | 8 ++++---- react/src/components/navigation/IonRouterOutlet.tsx | 11 +++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/react/src/components/createControllerComponent.tsx b/react/src/components/createControllerComponent.tsx index f467b071e10..84d0fba35d4 100644 --- a/react/src/components/createControllerComponent.tsx +++ b/react/src/components/createControllerComponent.tsx @@ -7,11 +7,11 @@ export function createControllerComponent) => void; } - type Props = T & ReactProps; + type Props = T & ReactControllerProps; return class ReactControllerComponent extends React.Component { element: E; diff --git a/react/src/components/createOverlayComponent.tsx b/react/src/components/createOverlayComponent.tsx index 09c11d81c89..d5b3a6c2e0a 100644 --- a/react/src/components/createOverlayComponent.tsx +++ b/react/src/components/createOverlayComponent.tsx @@ -9,14 +9,14 @@ export function createOverlayComponent) => void; } - type Props = T & ReactProps; + type Props = T & ReactOverlayProps; - return class ReactControllerComponent extends React.Component { + return class ReactOverlayComponent extends React.Component { element: E; controllerElement: C; el: HTMLDivElement; diff --git a/react/src/components/navigation/IonRouterOutlet.tsx b/react/src/components/navigation/IonRouterOutlet.tsx index c51823b7c4e..429db87ac8f 100644 --- a/react/src/components/navigation/IonRouterOutlet.tsx +++ b/react/src/components/navigation/IonRouterOutlet.tsx @@ -32,7 +32,7 @@ interface State { } interface ContextInterface { - goBack: () => void + goBack: (defaultHref?: string) => void } const Context = React.createContext({ @@ -152,11 +152,11 @@ class RouterOutlet extends Component { }); } - goBack = () => { + goBack = (defaultHref?: string) => { const prevView = this.state.views.find(v => v.id === this.state.activeId); const newView = this.state.views.find(v => v.id === prevView.prevId); - - this.props.history.replace(newView.location.pathname); + const newPath = newView ? newView.location.pathname : defaultHref; + this.props.history.replace(newPath); } componentDidUpdate() { @@ -232,8 +232,7 @@ export class IonBackButton extends Component { clickButton = (e: MouseEvent) => { e.stopPropagation(); - - this.context.goBack(); + this.context.goBack(this.props.defaultHref); } render() {