角度:路由器导航抛出JIT编译失败

时间:2020-06-17 09:26:33

标签: javascript angular typescript

在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';

但是我不知道为什么要修复它以及它可能有什么副作用。与“经典”路由的唯一区别在于,它位于命名的路由器出口上。

0 个答案:

没有答案