更新时间:2023-10-25 23:32:22
您可能会发现你在的文档为位置
类。在回()
功能可能会为你做。
You might find what you need in the docs for the Location
class. The back()
function could possibly do it for you.
另一种方法是订阅 popstate
事件位置
代替。 MDN有谈论你可以期望得到的值文档。
Another approach would be to subscribe to the popstate
events in Location
, instead. MDN has docs talking about the values you could expect to receive.
class MyCLass {
constructor(private location: Location) {
location.subscribe((val) => {
// do something with the state that's passed in
})
}
}
否则,你可能想,跟踪在路由器的转换服务,使您可以访问它们。
Otherwise you might want a service that tracks the changes in the Router so that you can access them.
class MyTrackingService {
constructor(private router: Router) {
router.subscribe((val) => {
// store the routes here so that you can peel them off as needed?
})
}
}
在这种情况下,我访问路由器
对象和订阅的任何变化,这样我可以跟踪他们。
In this case I'm accessing the Router
object and subscribing to any changes so that I could track them.