Skip to content

Commit c6b383e

Browse files
committed
fix: fixed bug where parameter n does not work in prepop method
1 parent 613d7c3 commit c6b383e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/lib/Router.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ export default class Router<Component> extends EventEmitter<IRouterEventMap<Comp
8080
};
8181
}
8282

83-
public prepop<T extends IPopNavigationOptions>(option?: Partial<T>): preActionCallback {
84-
const index = this.routeStack.length - 2;
83+
public prepop<T extends Partial<IPopNavigationOptions>>(option?: T): preActionCallback {
84+
let { n = 1 } = option || {};
85+
if (this.routeStack.length > 1 && n > this.routeStack.length - 1) {
86+
n = this.routeStack.length - 1;
87+
}
88+
const index = this.routeStack.length - n - 1;
8589

8690
if (index < 0) {
8791
return (cancel?: boolean) => undefined;
@@ -137,10 +141,10 @@ export default class Router<Component> extends EventEmitter<IRouterEventMap<Comp
137141
* @returns {void}
138142
* @memberof Router
139143
*/
140-
public pop<T extends IPopNavigationOptions>(option: Partial<T> = {}): void {
144+
public pop<T extends Partial<IPopNavigationOptions>>(option?: T): void {
141145
if (this.routeStack.length <= 1) return;
142-
let { n = 1 } = option;
143-
const { transition } = option;
146+
let { n = 1 } = option || {};
147+
const { transition } = option || {};
144148
if (n > this.routeStack.length - 1) {
145149
n = this.routeStack.length - 1;
146150
}

0 commit comments

Comments
 (0)