Skip to content

Commit 2dc8143

Browse files
committed
refactor: add nextId check
1 parent 6614145 commit 2dc8143

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/driver/Browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class BrowserDriver extends EventEmitter<IDriverEventMap> impleme
5252
}
5353
public push(path: string, state?: unknown, payload?: unknown): void {
5454
const id = this.nextId || IdGenerator.generateId();
55-
this.deprecateNextId();
55+
if (this.nextId) this.deprecateNextId();
5656
window.history.pushState({ __routeState: { id, state } } as IHistoryRouteState, '', this.getUrl(path));
5757
this.handleRouteChange(RouteActionType.PUSH, id, path, state, payload);
5858
}
@@ -67,7 +67,7 @@ export default class BrowserDriver extends EventEmitter<IDriverEventMap> impleme
6767

6868
public replace(path: string, state?: unknown, payload?: unknown): void {
6969
const id = this.nextId || IdGenerator.generateId();
70-
this.deprecateNextId();
70+
if (this.nextId) this.deprecateNextId();
7171
window.history.replaceState({ __routeState: { id, state } } as IHistoryRouteState, '', this.getUrl(path));
7272
this.handleRouteChange(RouteActionType.REPLACE, id, path, state, payload);
7373
}
@@ -100,7 +100,7 @@ export default class BrowserDriver extends EventEmitter<IDriverEventMap> impleme
100100
});
101101
}
102102
private handlePopstate(e: PopStateEvent) {
103-
this.deprecateNextId();
103+
if (this.nextId) this.deprecateNextId();
104104
const historyState = e.state as IHistoryRouteState | null;
105105
const routeState = historyState && historyState.__routeState;
106106
if (routeState) {
@@ -119,7 +119,7 @@ export default class BrowserDriver extends EventEmitter<IDriverEventMap> impleme
119119
}
120120

121121
private getInitRouteRecord(): IRouteRecord {
122-
const path = this.getCurrentPath() || '/';
122+
const path = this.getCurrentPath();
123123
let id: string;
124124
let state: unknown;
125125
const currentState = window.history.state as IHistoryRouteState;

src/driver/Server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class ServerDriver extends EventEmitter<IDriverEventMap> implemen
2626
public push(path: string, state?: unknown, payload?: unknown): void {
2727
const id = this.nextId || IdGenerator.generateId();
2828
this.stack.push({ id, path, state });
29-
this.deprecateNextId();
29+
if (this.nextId) this.deprecateNextId();
3030
this.handleRouteChange(RouteActionType.PUSH, id, path, state, payload);
3131
}
3232
public pop(n: number, payload?: unknown): void {
@@ -42,7 +42,7 @@ export default class ServerDriver extends EventEmitter<IDriverEventMap> implemen
4242
}
4343
public replace(path: string, state?: unknown, payload?: unknown): void {
4444
const id = this.nextId || IdGenerator.generateId();
45-
this.deprecateNextId();
45+
if (this.nextId) this.deprecateNextId();
4646
this.stack.pop();
4747
this.stack.push({ id, path, state });
4848
this.handleRouteChange(RouteActionType.REPLACE, id, path, state, payload);

0 commit comments

Comments
 (0)