我正在创建一个网站。在我的网站中,我正在尝试创建管理部分。在我的管理模块中,我有更多的组件,如登录、仪表板、产品等。但是在我的代码管理页面中,但子部分不像http: //localhost:4200/admin/adminlogin和http://localhost:4200/admin/admindashboard。我不知道如何在路由中使用孩子。只是我试过但没有工作。任何人都可以在我的代码中找到我的错误。
演示: https ://stackblitz.com/edit/angular-fixed-footer-header-zhdjw9?file=app/admin/admin.component.html
app.routing.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component'
import { AboutComponent } from './about/about.component'
import { LoginComponent } from './login/login.component';
import { AdminComponent } from './admin/admin.component';
const routes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
},
{
path: 'home',
component: HomeComponent,
},
{
path: 'about',
component: AboutComponent,
},
{
path: 'login',
component: LoginComponent,
},
{
path: 'admin',
component: AdminComponent,
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [
RouterModule
],
declarations: []
})
export class AppRoutingModule { }
admin.routing.ts:
const routes: Routes = [
{
path: 'admin', component: AdminComponent, children: [
{ path: 'adminlogin', component: AdminLoginComponent},
{ path: 'admindashboard', component: AdminDashboardComponent},
]
}
];