January 2018
Intermediate to advanced
332 pages
7h 36m
English
To add logic to the back button from here on is relatively simpler. When the user clicks on the Back button, we will navigate to the previous state of the application from the stack. If the stack was empty when the user clicks the Back button, meaning that the user is at the starting state, then we set it back into the stack because we do the pop() operation to determine the current state of the stack.
goBack() { let current = this.stack.pop(); let prev = this.stack.peek(); if (prev) { this.stack.pop(); // angular provides nice little method to // transition between the states using just the url if needed. this.router.navigateByUrl(prev.urlAfterRedirects); } else { this.stack.push(current); }}
Note here that we ...
Read now
Unlock full access