Angular2.0.0-rc1 async routers

2020-04-12 03:30发布

问题:

With latest changes from May 2016 (RC1) there is now @Routes, no more @RouteConfig where I could have used newAsyncRoute in order to async load the component.

The documentation is not yet ready at Angular.io, anybody knows how to use async router now with new routing, like in this case:

@Routes([
        { path: '/first', component: FirstComponent },
        { path: '/second', component: SecondComponent }
    ])

Thanks.

回答1:

This doesn't work in the new RC.3 router anymore. New ways for async routing seems to be on its way

Something like

@Routes([
    { path: '/first', component: 'app.first.component.js' },
    { path: '/second', component: 'app.second.component.js' }
])

See also https://github.com/angular/angular/issues/8861 and https://github.com/angular/angular/pull/8455/files (search for @Routes



标签: angular