是否可以防止导航时损坏Angular组件?

问题描述 投票:8回答:1

假设我有两个Angular 2组件:ComponentAComponentB。我希望能够从ComponentA导航到ComponentB,然后最终回到ComponentA,而不必重新初始化ComponentA。

在当前的Angular 2 Router实现中,每次我离开一个组件时,该组件都会被破坏,并且下次我导航到该组件时必须重新创建它。

我知道我可以通过使用Service来保留组件的状态,但这似乎比我的问题的实际解决方案更像是一种解决方法。有什么办法解决吗?

javascript angular typescript angular-router
1个回答
0
投票

是,是的,您需要实现RouteReuseStrategy

© www.soinside.com 2019 - 2024. All rights reserved.