Where is the lazy quoted route in Angular 2?

时光毁灭记忆、已成空白 提交于 2019-12-11 00:32:18

问题


I've watched this clarifying keynote in which Papa Misko presents the new routing system introduced in the RC version.

It's contained in the presentation the solution for the "Last Lazy Loading Puzzle Piece", and that relies on quoting the route component name as shown in his own example:

{path: 'simple', component: SimpleCmp}   // Non-lazy route
{path: 'simple', component: 'SimpleCmp'} // Lazy route

But its not working to me! The typescript compiler is complaining though. Here is the error:

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'.

It seems that is was not implemented yet. Does someone know what's going on and if it's really not implemented?


回答1:


At this time (06/08/16) it isn't finished yet, but if you're using webpack you can use a combination of es6-promise combined with webpack's require() to create your own "lazy-loading".

When the official lazy-loading comes out, you can just as easily remove this and use the upcoming standard Angular lazy-loader.

Take a look at the example here in 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') 
  }

])

Just make sure you have es6-promise installed and inside your package.json.

npm i es6-promise --save



来源:https://stackoverflow.com/questions/37702971/where-is-the-lazy-quoted-route-in-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!