路由儿童概念在8号角不起作用

问题描述 投票:0回答:1

我正在创建一个网站。在我的网站中,我正在尝试创建管理部件。在我的管理模块中,我有更多的组件,例如登录名,仪表板,产品等。但是在我的代码管理页面中,但是子部件无法正常工作http://localhost:4200/admin/adminloginhttp://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},
]
}
];
typescript angular7 angular2-routing angular8 angular7-router
1个回答
0
投票

由于在两个位置给出的admin路径之间存在冲突,因此无法正常工作。一个在* .module.ts文件中,另一个在* routing.module.ts文件中。您已经给定path =“ / admin”,并且在路由中您还声明了子路径。但是在运行时它是从* .module.ts文件中提取的。因此,要解决此问题,请在* .module.ts中声明您的孩子并清除routing.module.ts或从* .module中移动路由文件中的所有路由数组。 ts文件。这样可以解决您的问题。您可以在* module.ts文件中提供此快照代码

© www.soinside.com 2019 - 2024. All rights reserved.