Angular 2 中的惰性引用路由在哪里?
Where is the lazy quoted route in Angular 2?
我看过 this clarifying keynote,其中 Papa Misko 介绍了 RC 版本中引入的新路由系统。
它包含在演示文稿中 "Last Lazy Loading Puzzle Piece" 的解决方案,并且依赖于引用路由组件名称,如他自己的示例所示:
{path: 'simple', component: SimpleCmp} // Non-lazy route
{path: 'simple', component: 'SimpleCmp'} // Lazy route
但这对我不起作用!打字稿编译器虽然在抱怨。
这是错误:
Argument of type '{ path: string; component: string; }[]' is not assignable to parameter of type 'RouteMetadata[]'.
Type '{ path: string; component: string; }' is not assignable to type 'RouteMetadata'.
Types of property 'component' are incompatible.
Type 'string' is not assignable to type 'Type'.
好像还没有实现。
有人知道这是怎么回事吗,如果真的没有实施?
此时 (06/08/16) 还没有完成,但是如果你使用 webpack 你可以使用 es6-promise
的组合结合 webpack 的 require()
创建你自己的 "lazy-loading".
When the official lazy-loading comes out, you can just as easily remove this and use the upcoming standard Angular lazy-loader.
查看 angular2 webpack starter 中的示例。
@RouteConfig([
// Async load a component using Webpack's require
// with es6-promise-loader and webpack `require`
{
path: '/about', name: 'About',
loader: () => require('es6-promise!./about')('About')
}
])
只需确保您已安装 es6-promise
并在 package.json 内。
npm i es6-promise --save
我看过 this clarifying keynote,其中 Papa Misko 介绍了 RC 版本中引入的新路由系统。
它包含在演示文稿中 "Last Lazy Loading Puzzle Piece" 的解决方案,并且依赖于引用路由组件名称,如他自己的示例所示:
{path: 'simple', component: SimpleCmp} // Non-lazy route
{path: 'simple', component: 'SimpleCmp'} // Lazy route
但这对我不起作用!打字稿编译器虽然在抱怨。 这是错误:
Argument of type '{ path: string; component: string; }[]' is not assignable to parameter of type 'RouteMetadata[]'.
Type '{ path: string; component: string; }' is not assignable to type 'RouteMetadata'.
Types of property 'component' are incompatible.
Type 'string' is not assignable to type 'Type'.
好像还没有实现。 有人知道这是怎么回事吗,如果真的没有实施?
此时 (06/08/16) 还没有完成,但是如果你使用 webpack 你可以使用 es6-promise
的组合结合 webpack 的 require()
创建你自己的 "lazy-loading".
When the official lazy-loading comes out, you can just as easily remove this and use the upcoming standard Angular lazy-loader.
查看 angular2 webpack starter 中的示例。
@RouteConfig([
// Async load a component using Webpack's require
// with es6-promise-loader and webpack `require`
{
path: '/about', name: 'About',
loader: () => require('es6-promise!./about')('About')
}
])
只需确保您已安装 es6-promise
并在 package.json 内。
npm i es6-promise --save