- Hands-On Data Structures and Algorithms with JavaScript
- Kashyap Mukkamala
- 204字
- 2021-06-30 19:12:10
Navigating between states
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 are using urlAfterRedirects instead of plain url. This is because we do not care about all the hops a particular URL made before reaching its final form, so we can skip all the redirected paths that it encountered earlier and send the user directly to the final URL after the redirects. All we need is the final state to which we need to navigate our user because that's where they were before navigating to the current state.
- Mastering Visual Studio 2017
- Docker技術(shù)入門(mén)與實(shí)戰(zhàn)(第3版)
- Apache Karaf Cookbook
- Linux環(huán)境編程:從應(yīng)用到內(nèi)核
- C#程序設(shè)計(jì)基礎(chǔ):教程、實(shí)驗(yàn)、習(xí)題
- Elasticsearch Server(Third Edition)
- Visual C#.NET程序設(shè)計(jì)
- 運(yùn)用后端技術(shù)處理業(yè)務(wù)邏輯(藍(lán)橋杯軟件大賽培訓(xùn)教材-Java方向)
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- Node.js 12實(shí)戰(zhàn)
- 從零開(kāi)始學(xué)Android開(kāi)發(fā)
- 創(chuàng)意UI Photoshop玩轉(zhuǎn)移動(dòng)UI設(shè)計(jì)
- Java RESTful Web Service實(shí)戰(zhàn)
- Getting Started with JUCE
- 機(jī)器人ROS開(kāi)發(fā)實(shí)踐