Skip to content

Commit 3ad9247

Browse files
committed
fix: fixed limit of pop action
fix #28
1 parent 8612f72 commit 3ad9247

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

src/lib/Router.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,8 @@ export default class StackRouter<Component> extends BaseEventEmitter<RouterEvent
143143
* @memberof Router
144144
*/
145145
public pop<T extends Partial<PopNavigationOptions>>(option?: T): void {
146-
if (this.routeStack.length <= 1) return;
147-
let { n = 1 } = option || {};
146+
const { n = 1 } = option || {};
148147
const { transition } = option || {};
149-
if (n > this.routeStack.length - 1) {
150-
n = this.routeStack.length - 1;
151-
}
152148
const payload: DriverPayload = { transition };
153149
this.driver.pop(n, payload);
154150
}
@@ -312,7 +308,7 @@ export default class StackRouter<Component> extends BaseEventEmitter<RouterEvent
312308
case RouteActionType.POP:
313309
const index = this.routeStack.findIndex(i => routeInfo.route.id === i.route.id);
314310
if (index === -1) {
315-
this.routeStack.push(routeInfo);
311+
this.routeStack = [routeInfo];
316312
this.componentChange(type, transition);
317313
} else {
318314
const destroyedIds = this.routeStack

test/lib/Router.test.ts

+2-22
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ describe('src/lib/Router.ts', () => {
163163
});
164164
});
165165
describe('Router#pop', () => {
166-
it('empty stack should be ok', () => {
166+
it('empty stack should be ok', (done) => {
167167
class TestDriver extends ServerDriver {
168168
public pop(n: number, payload?: unknown): void {
169-
assert.fail('should not trigger');
169+
done()
170170
}
171171
}
172172
const routeManager = new RouteManager<RouteConfig<string>>();
@@ -196,26 +196,6 @@ describe('src/lib/Router.ts', () => {
196196
router.push('test1');
197197
router.pop();
198198
});
199-
it('the wrong parameter n should be ok', () => {
200-
class TestDriver extends ServerDriver {
201-
public pop(n: number, payload?: unknown): void {
202-
assert.equal(n, 2);
203-
assert.equal((payload as any).transition, undefined);
204-
}
205-
}
206-
const routes = [
207-
{
208-
path: 'test1',
209-
component: 'aa'
210-
}
211-
];
212-
const driver = new TestDriver();
213-
driver.push('/test1?a=2');
214-
const router = new StackRouter({ routes }, driver);
215-
driver.push('/test1?a=3');
216-
driver.push('/test1?a=4');
217-
router.pop({ n: 100 });
218-
});
219199
});
220200
it('Router#replace');
221201
it('Router#popToBottom', () => {

0 commit comments

Comments
 (0)