Aurelia页面生命周期 - 路由/渲染管道中的执行顺序

Nen*_*nad 3 aurelia aurelia-templating-router aurelia-router

当应用程序从一个URL导航到另一个URL时,Aurelia路由和呈现管道中的执行顺序是什么?

Ash*_*ant 6

有两个生命周期:

路由器生命周期是:

  1. 上一个屏幕 canDeactivate
  2. 下一个屏幕被实例化
  3. 下一个屏幕 canActivate
  4. 上一个屏幕 deactivate
  5. 下一个屏幕 activate
  6. 呈现下一个屏幕.

组件生命周期是:

加载时:

  1. created
  2. bind
  3. attached

卸载时:

  1. detached
  2. unbind

至于如何将所有这些组合在一起,只需将每个回调添加到两个路由页面并记录调用,即可显示:

Previous Page canDeactivate
Next Page canActivate
Previous Page deactivate
Next Page activate
Next Page created
Next Page bind
Previous Page detached
Previous Page unbind
Next Page attached
Run Code Online (Sandbox Code Playgroud)

如果我们包含原始答案中包含的路由器挂钩(步骤),那么它看起来像这样:

Previous Page canDeactivate
Authorize step
Next Page canActivate
Pre-activate step
Previous Page deactivate
Next Page activate
Pre-render step
Next Page created
Next Page bind
Post-render step
Previous Page detached
Previous Page unbind
Next Page attached
Run Code Online (Sandbox Code Playgroud)

我已经包含了两个,因为大多数应用程序都没有添加钩子.