简体   繁体   English

是否可以执行完整,真实的过渡到另一条路线,然后再过渡到Ember?

[英]Is it possible to perform a full, real transition to another route and transition back in Ember?

I am running into trouble when transitioning away from a route and then back to it not resulting in full transitions in Ember. 从路线过渡然后回到路线时,我遇到了麻烦,而Ember并未完全过渡。

To be more concrete, I have a route game.new that handles setting up a new game and then this transitions to game.play . 更具体地说,我有一个路由game.new ,它负责设置新游戏,然后过渡到game.play The user doens't need to do anything, and so the transition happens automatically in the afterModel hook. 用户不需要执行任何操作,因此转换将自动在afterModel挂钩中进行。 However, once a game is over, I would like to start a new game by transitioning back to game.new and then automatically transitioning back to game.play . 但是,一旦游戏结束,我想通过过渡到game.new来开始新游戏,然后自动过渡到game.play However, if I have the following hook in app/routes/game/new.js : 但是,如果我在app/routes/game/new.js具有以下钩子:

afterModel() {
  this.transitionTo('game.play', game);
}

This has the effect of not fully completing the transition and thus the game/play route is not fully torn down and set up again. 这具有未完全完成过渡的效果,因此game/play没有完全拆除并重新设置。

Is there a way to fully transition from game.play to game.new and then automatically transition back to game.play so that all the content in game.play is torn down and recreated? 有没有办法从全面过渡game.playgame.new ,然后自动转换回game.play使得所有内容game.play被拆掉重建?

From Rock and Roll with Ebberjs : 从Ebberjs的摇滚乐开始:

Controllers in Ember are singletons and thus are not torn down when their route is navigated away from or when their model changes. Ember中的控制器是单例的,因此当其路线离开或模型更改时,它们不会被拆除。 That means their properties persist while the app lives and anything that needs to be reset needs to be done manually. 这意味着它们的属性在应用程序运行期间会持续存在,需要重置的所有内容都需要手动完成。 (...) Each route has a resetController hook that will be called when the route is being exited or when the model for the route changes (...)每条路线都有一个resetController挂钩,当该路线退出或该路线的模型发生更改时,该挂钩将被调用

I tried to mimic your game with this twiddle : 我试图用这种旋转来模仿你的游戏:

resetController: function(controller,isExiting ) { 
    if(isExiting) {
    this.score=0;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM