mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
@ -9,7 +9,7 @@ import { StackManager } from './StackManager';
|
|||||||
|
|
||||||
interface NavManagerProps extends RouteComponentProps {
|
interface NavManagerProps extends RouteComponentProps {
|
||||||
onNavigateBack: (defaultHref?: string) => void;
|
onNavigateBack: (defaultHref?: string) => void;
|
||||||
onNavigate: (type: 'push' | 'replace' | 'pop', path: string, state?: any) => void;
|
onNavigate: (ionRouteAction: IonRouteAction, path: string, state?: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NavManager extends React.Component<NavManagerProps, NavContextState> {
|
export class NavManager extends React.Component<NavManagerProps, NavContextState> {
|
||||||
|
@ -88,7 +88,7 @@ class RouteManager extends React.Component<RouteComponentProps, RouteManagerStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
historyChange(location: HistoryLocation, action: HistoryAction) {
|
historyChange(location: HistoryLocation, action: HistoryAction) {
|
||||||
const ionRouteAction = this.currentIonRouteAction === 'pop' ? 'pop' : action.toLowerCase();
|
const ionRouteAction = this.currentIonRouteAction === 'pop' ? 'pop' : action.toLowerCase() as IonRouteAction;
|
||||||
let direction = this.currentRouteDirection;
|
let direction = this.currentRouteDirection;
|
||||||
|
|
||||||
if (ionRouteAction === 'push') {
|
if (ionRouteAction === 'push') {
|
||||||
@ -101,6 +101,11 @@ class RouteManager extends React.Component<RouteComponentProps, RouteManagerStat
|
|||||||
direction = 'none';
|
direction = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (direction === 'root') {
|
||||||
|
this.locationHistory.clear();
|
||||||
|
this.locationHistory.add(location);
|
||||||
|
}
|
||||||
|
|
||||||
location.state = location.state || { direction };
|
location.state = location.state || { direction };
|
||||||
this.setState({
|
this.setState({
|
||||||
location,
|
location,
|
||||||
@ -175,8 +180,15 @@ class RouteManager extends React.Component<RouteComponentProps, RouteManagerStat
|
|||||||
const enteringEl = this.ionPageElements[enteringView.id];
|
const enteringEl = this.ionPageElements[enteringView.id];
|
||||||
const leavingEl = leavingView && this.ionPageElements[leavingView.id];
|
const leavingEl = leavingView && this.ionPageElements[leavingView.id];
|
||||||
if (enteringEl) {
|
if (enteringEl) {
|
||||||
// Don't animate from an empty view
|
let navDirection: NavDirection | undefined;
|
||||||
const navDirection = leavingEl && leavingEl.innerHTML === '' ? undefined : direction === 'none' ? undefined : direction;
|
if (leavingEl && leavingEl.innerHTML === '') {
|
||||||
|
// Don't animate from an empty view
|
||||||
|
navDirection = undefined;
|
||||||
|
} else if (direction === 'none' || direction === 'root') {
|
||||||
|
navDirection = undefined;
|
||||||
|
} else {
|
||||||
|
navDirection = direction;
|
||||||
|
}
|
||||||
const shouldGoBack = !!enteringView.prevId;
|
const shouldGoBack = !!enteringView.prevId;
|
||||||
const routerOutlet = this.routerOutlets[viewStack.id];
|
const routerOutlet = this.routerOutlets[viewStack.id];
|
||||||
this.commitView(
|
this.commitView(
|
||||||
|
@ -3,7 +3,7 @@ import { Location as HistoryLocation } from 'history';
|
|||||||
const RESTRICT_SIZE = 25;
|
const RESTRICT_SIZE = 25;
|
||||||
|
|
||||||
export class LocationHistory {
|
export class LocationHistory {
|
||||||
locationHistory: HistoryLocation[] = [];
|
private locationHistory: HistoryLocation[] = [];
|
||||||
|
|
||||||
add(location: HistoryLocation) {
|
add(location: HistoryLocation) {
|
||||||
this.locationHistory.push(location);
|
this.locationHistory.push(location);
|
||||||
@ -21,6 +21,10 @@ export class LocationHistory {
|
|||||||
this.locationHistory.push(location);
|
this.locationHistory.push(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this.locationHistory = [];
|
||||||
|
}
|
||||||
|
|
||||||
findLastLocationByUrl(url: string) {
|
findLastLocationByUrl(url: string) {
|
||||||
for (let i = this.locationHistory.length - 1; i >= 0; i--) {
|
for (let i = this.locationHistory.length - 1; i >= 0; i--) {
|
||||||
const location = this.locationHistory[i];
|
const location = this.locationHistory[i];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export declare type RouterDirection = 'forward' | 'back' | 'none';
|
export declare type RouterDirection = 'forward' | 'back' | 'root' | 'none';
|
||||||
|
|
||||||
export type HrefProps<T> = Omit<T, 'routerDirection'> & {
|
export type HrefProps<T> = Omit<T, 'routerDirection'> & {
|
||||||
routerLink?: string;
|
routerLink?: string;
|
||||||
|
Reference in New Issue
Block a user