Skip to content

Commit

Permalink
Merge pull request #439 from aurelia/jwx-router-redirecting
Browse files Browse the repository at this point in the history
Dynamic routing: remove redirect from history browser
  • Loading branch information
fkleuver committed Feb 15, 2019
2 parents 1a9f268 + 2cce2c2 commit 1f9d50c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
13 changes: 1 addition & 12 deletions packages/router/src/history-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class HistoryBrowser {
private isActive: boolean;

private lastHistoryMovement: number;
private cancelRedirectHistoryMovement: number;
private isReplacing: boolean;
private isRefreshing: boolean;

Expand All @@ -64,7 +63,6 @@ export class HistoryBrowser {
this.isActive = false;

this.lastHistoryMovement = null;
this.cancelRedirectHistoryMovement = null;
this.isReplacing = false;
this.isRefreshing = false;
}
Expand Down Expand Up @@ -109,11 +107,6 @@ export class HistoryBrowser {
};
return this.setPath(path, true);
}
public redirect(path: string, title?: string, data?: Record<string, unknown>): Promise<void> {
// This makes sure we can cancel redirects from both pushes and replaces
this.cancelRedirectHistoryMovement = this.lastHistoryMovement + 1;
return this.replace(path, title, data);
}

public async refresh(): Promise<void> {
if (!this.currentEntry) {
Expand All @@ -132,7 +125,7 @@ export class HistoryBrowser {
}

public cancel(): Promise<void> {
const movement = this.lastHistoryMovement || this.cancelRedirectHistoryMovement;
const movement = this.lastHistoryMovement;
if (movement) {
this.lastHistoryMovement = 0;
return this.history.go(-movement, true);
Expand Down Expand Up @@ -292,10 +285,6 @@ export class HistoryBrowser {
}
this.activeEntry = null;

if (this.cancelRedirectHistoryMovement) {
this.cancelRedirectHistoryMovement--;
}

Reporter.write(10000, 'navigated', this.getState('HistoryEntry'), this.historyEntries, this.getState('HistoryOffset'));
this.callback(this.currentEntry, navigationFlags, previousEntry);
}
Expand Down
11 changes: 0 additions & 11 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class Router {

private options: IRouterOptions;
private isActive: boolean = false;
private isRedirecting: boolean = false;

private readonly pendingNavigations: INavigationInstruction[] = [];
private processingNavigation: INavigationInstruction = null;
Expand Down Expand Up @@ -196,16 +195,6 @@ export class Router {
}
}

// We've gone via a redirected route back to same viewport status so
// we need to remove the added history entry for the redirect
// TODO: Take care of empty subsets/iterations where previous has length
if (!changedViewports.length && this.isRedirecting) {
const result = this.cancelNavigation([...changedViewports, ...updatedViewports], instruction);
this.isRedirecting = false;
await this.processNavigations();
return result;
}

let results = await Promise.all(changedViewports.map((value) => value.canLeave()));
if (results.findIndex((value) => value === false) >= 0) {
return this.cancelNavigation([...changedViewports, ...updatedViewports], instruction);
Expand Down

0 comments on commit 1f9d50c

Please sign in to comment.