mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
fix(react): support navigating to same page and route updates in IonRouterOutlet, fixes #19891, #19892, #19986
This commit is contained in:
@ -69,12 +69,13 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
|
||||
}
|
||||
|
||||
private onTabButtonClick = (e: CustomEvent<{ href: string, selected: boolean, tab: string }>) => {
|
||||
const originalHref = this.state.tabs[e.detail.tab].originalHref;
|
||||
const currentHref = this.state.tabs[e.detail.tab].currentHref;
|
||||
if (this.state.activeTab === e.detail.tab) {
|
||||
const originalHref = this.state.tabs[e.detail.tab].originalHref;
|
||||
if (this.context.hasIonicRouter()) {
|
||||
this.context.tabNavigate(originalHref);
|
||||
if (originalHref === currentHref) {
|
||||
this.context.navigate(originalHref, 'none');
|
||||
} else {
|
||||
this.context.navigate(originalHref, 'back');
|
||||
this.context.navigate(originalHref, 'back', 'replace');
|
||||
}
|
||||
} else {
|
||||
if (this.props.onIonTabsWillChange) {
|
||||
@ -83,7 +84,7 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
|
||||
if (this.props.onIonTabsDidChange) {
|
||||
this.props.onIonTabsDidChange(new CustomEvent('ionTabDidChange', { detail: { tab: e.detail.tab } }));
|
||||
}
|
||||
this.context.navigate(this.state.tabs[e.detail.tab].currentHref, 'none');
|
||||
this.context.navigate(currentHref, 'none');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,10 +5,9 @@ export interface NavContextState {
|
||||
getPageManager: () => any;
|
||||
getStackManager: () => any;
|
||||
goBack: (defaultHref?: string) => void;
|
||||
navigate: (path: string, direction?: RouterDirection | 'none') => void;
|
||||
navigate: (path: string, direction?: RouterDirection | 'none', type?: 'push' | 'replace') => void;
|
||||
hasIonicRouter: () => boolean;
|
||||
registerIonPage: (page: HTMLElement) => void;
|
||||
tabNavigate: (url: string) => void;
|
||||
currentPath: string | undefined;
|
||||
}
|
||||
|
||||
@ -23,7 +22,6 @@ export const NavContext = /*@__PURE__*/React.createContext<NavContextState>({
|
||||
}
|
||||
},
|
||||
navigate: (path: string) => { window.location.pathname = path; },
|
||||
tabNavigate: () => undefined,
|
||||
hasIonicRouter: () => false,
|
||||
registerIonPage: () => undefined,
|
||||
currentPath: undefined
|
||||
|
||||
Reference in New Issue
Block a user