Angular Can';不要从另一个模块跳转
我是新来的。我做了说明中的所有操作,但有点错误:我无法加载外部模块中定义/路由的组件 -此代码非常简单。只有3个链接和几个空组件。(Angular Can';不要从另一个模块跳转,angular,router,Angular,Router,我是新来的。我做了说明中的所有操作,但有点错误:我无法加载外部模块中定义/路由的组件 -此代码非常简单。只有3个链接和几个空组件。(app为了简单起见,组件和模块被合并到一个app.ts中) 请查看产品.module.ts。有一句话: @NgModule({ imports: [ RouterModule.forChild( [ { path: 'products', component: ProductsComponent }, // <--- t
app
为了简单起见,组件和模块被合并到一个app.ts中)
请查看产品.module.ts。有一句话:
@NgModule({
imports:
[
RouterModule.forChild(
[
{ path: 'products', component: ProductsComponent }, // <--- this goes to NotFoundComponent :(
])
],
declarations: [ ProductsComponent ]
})
@NgModule({
进口:
[
RouterModule.forChild(
[
{path:'products',component:ProductsComponent},//在app.module
中切换路由模块
imports:
[
BrowserModule,
/* RouterModule.forRoot([
{ path: 'welcome', component: WelcomeComponent },
{ path: 'contact', component: ContactComponent },
{ path: '', component: TestComponent },
{ path: '**', component: NotFoundComponent },
]),*/
ProductsModule, //<-- this needs to be above main routing module
AppRoutingModule
]
导入:
[
浏览器模块,
/*RouterModule.forRoot([
{路径:“欢迎”,组件:WelcomeComponent},
{路径:'contact',组件:ContactComponent},
{路径:'',组件:TestComponent},
{路径:'**',组件:NotFoundComponent},
]),*/
ProductsModule,//@tBlabs很高兴能为您提供帮助:-)