Why do my angular2 components get re-instantiated each time I change the route?

前端 未结 3 946
-上瘾入骨i
-上瘾入骨i 2021-01-17 12:14

I am trying to put together a demo app of Angular 2 + Rx.JS 5/Next.

I noticed that my components are re-instantiated each time I switch the route.

3条回答
  •  醉酒成梦
    2021-01-17 12:37

    "It is absolutely expected behavior that the components will be constructed and destructed as your route changes"

    The point is that components should NOT be reconstructed again and again as one navigates back and forth between two links (that are different from each other). What if you have complex graphics and state that you are modifying on one link and the object is destroyed and recreated as you arrive back to resume your work?

    A framework should not dictate if the objects should be destroyed and recreated again and again. It should provide both options and in the default option, it should NOT destroy and recreate as this is the intuitive behavior. This is the behavior most UI frameworks have used over the years.

提交回复
热议问题