【发布时间】:2018-04-29 20:45:34
【问题描述】:
在我的 Angular 应用程序中,当我打开链接 localhost:4200(应用程序在其上提供服务)时,我希望我的应用程序将我重定向到 localhost:4200/notes。我想查看notes-component的数据,它包含在主组件中。
示例(html 页面中的文本):
App component
Main component
Notes-page component
但是我只能看到 localhost:4200(没有重定向)和 notes-component 的数据,没有 main 组件。
示例(html 页面中的文本):
App component
Notes-page component
为什么会这样?以及如何纠正?
文件结构:
/app
/containers
/main
/notes-page
notes-page.routing.ts
notes-page.component.ts
notes-page.module.ts
main.routing.ts
main.component.ts
main.module.ts
app.routing.ts
app.component.ts
app.module.ts
文件:
app.routing.ts
export const routing: ModuleWithProviders = RouterModule.forRoot([
{
path: '',
loadChildren: './containers/main/main.module#MainModule'
}
]);
app.component.html
<h5>App component</h5>
<router-outlet></router-outlet>
main.module.ts
export const routing: ModuleWithProviders = RouterModule.forChild([
{
path: '',
component: MainComponent,
children: [
{
path: '',
redirectTo: 'notes',
pathMatch: 'full'
},
{
path: 'notes',
loadChildren: './notes-page/notes-page.module#NotesPageModule'
}
]
}
]);
main.component.html
<h5>Main component</h5>
<main>
<router-outlet></router-outlet>
</main>
notes-page.module.ts
export const routing: ModuleWithProviders = RouterModule.forChild([
{
path: '',
pathMatch: 'full',
component: NotesPageComponent
}
]);
notes-page.component.html
<h5>Notes-page component</h5>
【问题讨论】:
-
在此处添加 pathMatch: 'full' : path: '', loadChildren: './containers/main/main.module#MainModule'
-
没用。
-
但感谢您的回答
标签: javascript angular routing