@@ -6,7 +6,6 @@ import { IonTabBarInner } from '../inner-proxies';
6
6
import { IonTabButton } from '../proxies' ;
7
7
8
8
type Props = LocalJSX . IonTabBar & {
9
- navigate ?: ( path : string , direction : 'back' | 'none' ) => void ;
10
9
currentPath ?: string ;
11
10
slot ?: 'bottom' | 'top' ;
12
11
} ;
@@ -22,6 +21,7 @@ interface State {
22
21
}
23
22
24
23
const IonTabBarUnwrapped = /*@__PURE__ */ ( ( ) => class extends React . Component < Props , State > {
24
+ context ! : React . ContextType < typeof NavContext > ;
25
25
26
26
constructor ( props : Props ) {
27
27
super ( props ) ;
@@ -67,13 +67,15 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
67
67
}
68
68
69
69
private onTabButtonClick = ( e : CustomEvent < { href : string , selected : boolean , tab : string } > ) => {
70
- const { navigate } = this . props ;
71
- if ( navigate ) {
72
- if ( this . state . activeTab === e . detail . tab ) {
73
- navigate ( this . state . tabs [ e . detail . tab ] . originalHref , 'back' ) ;
70
+ if ( this . state . activeTab === e . detail . tab ) {
71
+ const originalHref = this . state . tabs [ e . detail . tab ] . originalHref ;
72
+ if ( this . context . hasIonicRouter ( ) ) {
73
+ this . context . goBack ( originalHref ) ;
74
74
} else {
75
- navigate ( this . state . tabs [ e . detail . tab ] . currentHref , 'none ' ) ;
75
+ this . context . navigate ( originalHref , 'back ' ) ;
76
76
}
77
+ } else {
78
+ this . context . navigate ( this . state . tabs [ e . detail . tab ] . currentHref , 'none' ) ;
77
79
}
78
80
}
79
81
@@ -96,16 +98,17 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
96
98
</ IonTabBarInner >
97
99
) ;
98
100
}
101
+
102
+ static get contextType ( ) {
103
+ return NavContext ;
104
+ }
99
105
} ) ( ) ;
100
106
101
107
export const IonTabBar : React . FC < Props > = props => {
102
108
const context = useContext ( NavContext ) ;
103
109
return (
104
110
< IonTabBarUnwrapped
105
111
{ ...props as any }
106
- navigate = { props . navigate || ( ( path : string , direction : 'back' | 'none' ) => {
107
- context . navigate ( path , direction ) ;
108
- } ) }
109
112
currentPath = { props . currentPath || context . currentPath }
110
113
>
111
114
{ props . children }
0 commit comments