【问题标题】:How to Handle Routes for Module from NPM如何从 NPM 处理模块的路由
【发布时间】:2017-08-18 19:00:39
【问题描述】:

我有一个从 NPM 模块加载的 Angular 模块。如何从中加载路线?这是我的 app.module.ts 文件中的一个 sn-p:

import { HelloWorldModule } from 'hello-world-app-npm/hello-world-app.umd.js'; // The module loaded from NPM

const routes = [
{ path: 'hw', loadChildren: () => HelloWorldModule },
{ path: '', component: AppComponent },
]

@NgModule({
declarations: [
    AppComponent
],
imports: [
    BrowserModule,
    HelloWorldModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot(routes)
],
exports: [RouterModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

这是我定义我的 hello world 模块的方式:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HelloWorldComponent } from './hello-world.component';

export const routes = [{ path: '', component: HelloWorldComponent }]

@NgModule({
    bootstrap: [HelloWorldComponent],
    declarations: [
        HelloWorldComponent
    ],
    imports: [
        RouterModule.forChild(routes)
    ]
})
export class HelloWorldModule {
}

当我转到“/hw”时,我在 chrome 中收到错误提示

未捕获(承诺中):RangeError:超出最大调用堆栈大小

我做错了什么?我该如何解决这个问题?

【问题讨论】:

  • 如何重现您的问题?

标签: javascript node.js angular angular2-routing


【解决方案1】:

我怀疑这可能是因为两件事。

  1. HelloWorldModule 不应出现在 AppModule 导入中。
  2. bootstrap: [HelloWorldComponent]HelloWorldModule 是不必要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    相关资源
    最近更新 更多