Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nativescript-angular/router/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export class NSLocationStrategy extends LocationStrategy {

}

canGoBack() {
return this.states.length > 1;
}

onPopState(fn: (_: any) => any): void {
routerLog("NSLocationStrategy.onPopState");
this.popStateCallbacks.push(fn);
Expand Down
4 changes: 4 additions & 0 deletions nativescript-angular/router/router-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class RouterExtensions {
this.locationStrategy.back();
}

public canGoBack() {
return this.locationStrategy.canGoBack();
}

public backToPreviousPage() {
this.frame.goBack();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/app/tests/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ describe('NSLocationStrategy', () => {
assert.equal(strategy.path(), "/test");
});

it("canGoBack() return false initially", () => {
const strategy = initStrategy();

assert.isFalse(strategy.canGoBack(), "canGoBack() should reutrn false if there are no navigations");
});

it("canGoBack() return true after navigation", () => {
const strategy = initStrategy();

strategy.pushState(null, "test", "/test", null);

assert.isTrue(strategy.canGoBack(), "canGoBack() should reutrn true after navigation");
});

it("back() calls onPopState", () => {
const strategy = initStrategy();
let popCount = 0;
Expand Down