mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 10:41:13 +08:00
chore(react): fixing test and another method to tab nav
This commit is contained in:
@ -33,7 +33,8 @@ export class NavManager extends React.Component<NavManagerProps, NavContextState
|
|||||||
getStackManager: this.getStackManager.bind(this),
|
getStackManager: this.getStackManager.bind(this),
|
||||||
getPageManager: this.getPageManager.bind(this),
|
getPageManager: this.getPageManager.bind(this),
|
||||||
currentPath: this.props.location.pathname,
|
currentPath: this.props.location.pathname,
|
||||||
registerIonPage: () => { return; } // overridden in View for each IonPage
|
registerIonPage: () => { return; }, // overridden in View for each IonPage
|
||||||
|
tabNavigate: this.tabNavigate.bind(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listenUnregisterCallback = this.props.history.listen((location: HistoryLocation) => {
|
this.listenUnregisterCallback = this.props.history.listen((location: HistoryLocation) => {
|
||||||
@ -93,6 +94,10 @@ export class NavManager extends React.Component<NavManagerProps, NavContextState
|
|||||||
this.props.history.push(path, { direction });
|
this.props.history.push(path, { direction });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tabNavigate(url: string) {
|
||||||
|
this.props.history.replace(url, { direction: 'back' });
|
||||||
|
}
|
||||||
|
|
||||||
getPageManager() {
|
getPageManager() {
|
||||||
return (children: any) => children;
|
return (children: any) => children;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ describe('IonTabs', () => {
|
|||||||
const { container } = render(
|
const { container } = render(
|
||||||
<IonTabs>
|
<IonTabs>
|
||||||
<IonRouterOutlet></IonRouterOutlet>
|
<IonRouterOutlet></IonRouterOutlet>
|
||||||
<IonTabBar slot="bottom" currentPath={'/'} navigate={() => {}}>
|
<IonTabBar slot="bottom" currentPath={'/'}>
|
||||||
<IonTabButton tab="schedule">
|
<IonTabButton tab="schedule">
|
||||||
<IonLabel>Schedule</IonLabel>
|
<IonLabel>Schedule</IonLabel>
|
||||||
<IonIcon name="schedule"></IonIcon>
|
<IonIcon name="schedule"></IonIcon>
|
||||||
@ -44,7 +44,7 @@ describe('IonTabs', () => {
|
|||||||
const { container } = render(
|
const { container } = render(
|
||||||
<IonTabs>
|
<IonTabs>
|
||||||
<IonRouterOutlet></IonRouterOutlet>
|
<IonRouterOutlet></IonRouterOutlet>
|
||||||
<IonTabBar slot="bottom" currentPath={'/'} navigate={() => {}}>
|
<IonTabBar slot="bottom" currentPath={'/'}>
|
||||||
{false &&
|
{false &&
|
||||||
<IonTabButton tab="schedule">
|
<IonTabButton tab="schedule">
|
||||||
<IonLabel>Schedule</IonLabel>
|
<IonLabel>Schedule</IonLabel>
|
||||||
|
@ -70,7 +70,7 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component<Pro
|
|||||||
if (this.state.activeTab === e.detail.tab) {
|
if (this.state.activeTab === e.detail.tab) {
|
||||||
const originalHref = this.state.tabs[e.detail.tab].originalHref;
|
const originalHref = this.state.tabs[e.detail.tab].originalHref;
|
||||||
if (this.context.hasIonicRouter()) {
|
if (this.context.hasIonicRouter()) {
|
||||||
this.context.goBack(originalHref);
|
this.context.tabNavigate(originalHref);
|
||||||
} else {
|
} else {
|
||||||
this.context.navigate(originalHref, 'back');
|
this.context.navigate(originalHref, 'back');
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ export interface NavContextState {
|
|||||||
navigate: (path: string, direction?: RouterDirection | 'none') => void;
|
navigate: (path: string, direction?: RouterDirection | 'none') => void;
|
||||||
hasIonicRouter: () => boolean;
|
hasIonicRouter: () => boolean;
|
||||||
registerIonPage: (page: HTMLElement) => void;
|
registerIonPage: (page: HTMLElement) => void;
|
||||||
|
tabNavigate: (url: string) => void;
|
||||||
currentPath: string | undefined;
|
currentPath: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ export const NavContext = /*@__PURE__*/React.createContext<NavContextState>({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
navigate: (path: string) => { window.location.pathname = path; },
|
navigate: (path: string) => { window.location.pathname = path; },
|
||||||
|
tabNavigate: () => undefined,
|
||||||
hasIonicRouter: () => false,
|
hasIonicRouter: () => false,
|
||||||
registerIonPage: () => undefined,
|
registerIonPage: () => undefined,
|
||||||
currentPath: undefined
|
currentPath: undefined
|
||||||
|
Reference in New Issue
Block a user