我在 Angular 中遇到了一些简单的路由管理:我有第一个模块:
import { NgModule } from '@angular/core'; import { Routes } from '@angular/router'; import { RouterModule } from '@angular/router'; import { LayoutComponent } from './ui/components/layout/layout.component'; const routes: Routes = [{ path: '**', component: LayoutComponent, children: [ { path: '', redirectTo: '/posts', pathMatch: 'full'}, { path: 'posts',loadChildren: './posts/posts.module#PostsModule' }] }]; @NgModule({ imports: [RouterModule.forRoot(routes) ], exports: [RouterModule] }) export class AppRoutingModule { }
以及应该显示简单的“它有效”组件的“PostModule”:
import { NgModule } from '@angular/core';\n import { Routes } from '@angular/router';\n import { RouterModule } from '@angular/router'; import { PostsComponent } from './containers/posts/posts.component'; import { ProfileComponent } from './containers/profile/profile.component'; const routes: Routes = [{ path: '', component: PostsComponent },{ path: ':profileId', component: ProfileComponent },]; @NgModule({ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) export class PostsRoutingModule { }
但没有一条路线
显示预期内容
我想我错过了一些简单的东西,我的 app.component 看起来像这样:
<router-outlet> <router-outlet></router-outlet> </router-outlet>
我已经阅读了一些关于“延迟加载”的帖子,但是我所写的内容与我到目前为止所学的内容似乎是一致的,错误在哪里?