- 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.
- Spring 5.0 Microservices(Second Edition)
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- Java技術(shù)手冊(cè)(原書第7版)
- Koa開(kāi)發(fā):入門、進(jìn)階與實(shí)戰(zhàn)
- 零基礎(chǔ)學(xué)Java程序設(shè)計(jì)
- Building an RPG with Unity 2018
- Hands-On Natural Language Processing with Python
- Angular應(yīng)用程序開(kāi)發(fā)指南
- Delphi開(kāi)發(fā)典型模塊大全(修訂版)
- MyBatis 3源碼深度解析
- 深入理解Kafka:核心設(shè)計(jì)與實(shí)踐原理
- Enterprise Application Architecture with .NET Core
- 區(qū)塊鏈:技術(shù)與場(chǎng)景
- PHP從入門到精通(微視頻精編版)
- Scala實(shí)用指南