@@ -65,32 +65,33 @@ export class Tabs implements NavOutlet {
6565 this . ionNavWillLoad . emit ( ) ;
6666 }
6767
68- componentWillRender ( ) {
68+ componentDidLoad ( ) {
69+ this . updateTabBar ( ) ;
70+ }
71+
72+ componentDidUpdate ( ) {
73+ this . updateTabBar ( ) ;
74+ }
75+
76+ private updateTabBar ( ) {
6977 const tabBar = this . el . querySelector ( 'ion-tab-bar' ) ;
70- if ( tabBar ) {
71- let tab = this . selectedTab ? this . selectedTab . tab : undefined ;
72-
73- // Fallback: if no selectedTab is set but we're using router mode,
74- // determine the active tab from the current URL. This works around
75- // timing issues in React Router integration where setRouteId may not
76- // be called in time for the initial render.
77- // TODO(FW-6724): Remove this with React Router upgrade
78- if ( ! tab && this . useRouter && typeof window !== 'undefined' ) {
79- const currentPath = window . location . pathname ;
80- const tabButtons = this . el . querySelectorAll ( 'ion-tab-button' ) ;
81-
82- // Look for a tab button that matches the current path pattern
83- for ( const tabButton of tabButtons ) {
84- const tabId = tabButton . getAttribute ( 'tab' ) ;
85- if ( tabId && currentPath . includes ( tabId ) ) {
86- tab = tabId ;
87- break ;
88- }
89- }
90- }
78+ if ( ! tabBar ) {
79+ return ;
80+ }
9181
92- tabBar . selectedTab = tab ;
82+ const tab = this . selectedTab ? this . selectedTab . tab : undefined ;
83+
84+ // If tabs has no selected tab but tab-bar already has a selected-tab set,
85+ // don't overwrite it. This handles cases where tab-bar is used without ion-tab elements.
86+ if ( tab === undefined ) {
87+ return ;
88+ }
89+
90+ if ( tabBar . selectedTab === tab ) {
91+ return ;
9392 }
93+
94+ tabBar . selectedTab = tab ;
9495 }
9596
9697 /**
@@ -162,6 +163,7 @@ export class Tabs implements NavOutlet {
162163 this . selectedTab = selectedTab ;
163164 this . ionTabsWillChange . emit ( { tab : selectedTab . tab } ) ;
164165 selectedTab . active = true ;
166+ this . updateTabBar ( ) ;
165167 return Promise . resolve ( ) ;
166168 }
167169
0 commit comments