How *not* to destroy View when exiting a route in Ember.js

前端 未结 2 643
后悔当初
后悔当初 2021-02-02 00:32

Regarding the new Ember.js routing system (described here), if I understand correctly, views are destroyed when you exit a route.

Is there any way to bypass destruction

2条回答
  •  庸人自扰
    2021-02-02 01:09

    So that the state of the view is preserved when the user re-enters the route.

    I would, instead, store that information in the controller (or the state manager) so that when the route is re-entered, the new view is initialized with the old state. Does that make sense? So, for example, if it's a list of posts, and one is selected, you would store the data about which post was selected in the controller (or the state manager). After visiting a specific post and then coming back to the list, that same post would be selected.

    I can imagine a use case where this wouldn't be very useful (e.g. scrolling to a specific position in a long list) so maybe that doesn't answer your question.

提交回复
热议问题