在Angular9中,我尝试做一个:
this.router.navigate(['my-route']);
它是在我的app-routing.module.ts
{
path: 'my-route',
loadChildren: () => import('./custom/custom.module').then(m => m.CustomModule),
outlet: 'custom'
},
和
CustomModule
具有以下路线:
{
path: '',
component: CustomComponent
}
当我触发navigate
时,我得到:
Uncaught Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
我实际上通过添加到我的main.ts
import '@angular/compiler';
但是我不知道为什么要修复它以及它可能有什么副作用。与“经典”路由的唯一区别在于,它位于命名的路由器出口上。