术语 'Lazy State Definitions' 在引用 $stateChangeNotFound 时是什么意思

What does the term 'Lazy State Definitions' mean in reference to $stateChangeNotFound

我正在观看关于 ui-router 的视频,演讲者 (Tim Kindberg) 提到 $stateChangeNotFound 有利于惰性状态定义。他的意思是什么,在什么情况下使用?

我假设它与我理解的术语延迟加载有关。 AngularJS/ui-router 的新手,在此先感谢您的帮助。

延迟加载是指在运行时加载代码,即时。在此上下文中,它可能意味着 creating/defining 只有当用户尝试导航到状态(尚不存在)时的状态。

例如:

  • 存在这些状态是因为它们已在配置时声明

    1. a: { url: '/a' }
    2. b: { url: '/b' }
  • 用户点击 link 到 /c

  • $stateNotFound 事件在根作用域上触发
  • 应用程序侦听 $stateNotFound 事件
  • 应用程序为新状态加载状态定义(从服务器等)c: { url: '/c' }
  • 一旦状态定义被延迟加载,应用程序就会手动重新触发 ui-router 以同步 url '/c',并且 ui-router 路由到现在新创建的状态 c.

查看 UI-Router Extras Future States 以了解此模式的实现。