gpt4 book ai didi

routes - Angular 6 带有延迟加载的子路由

转载 作者:行者123 更新时间:2023-12-02 16:08:51 25 4
gpt4 key购买 nike

我必须访问技能路线,但对我来说这是不可能的。我尝试了很多方法,但无法按照代码结构访问技能路线。我的想法是能够访问仪表板模块的子路径

提前非常感谢您。

// app.routing.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

// components for route controller
import { HomeComponent } from './components/home/home.component';

const routes: Routes = [
{
path: '', redirectTo: 'home', pathMatch: 'full'
},
{
path: 'home', component: HomeComponent
},
{
path: 'dashboard',
loadChildren: '../app/modules/dashboard/dashboard.module#DashboardModule'
}

];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

...

// dashboard.routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

// AuthGuardService

import { AuthGuard } from '../../shared/guards/auth-guard.service';

// routing components
import { DashboardComponent } from './dashboard.component';
import { DashboardHomeComponent } from './components/dashboard-home/dashboard-home.component';
import { SkillsComponent } from './components/skills/skills.component';

const routes: Routes = [
{
path: '',
component: DashboardComponent,
canActivate: [AuthGuard],
children: [
{
path: '',
component: DashboardHomeComponent,
outlet: "dashboard"
},
{
path: 'skills',
component: SkillsComponent,
outlet: "dashboard"
}
]
}

];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DashboardRoutingModule { }

最佳答案

确保 DashboardModule 导入 DashboardRoutingModule

// dashboard.module.ts

...
import DashboardRoutingModule from './dashboard.routing.module.ts'.

@NgModule({
imports: [DashboardRoutingModule]
});

关于routes - Angular 6 带有延迟加载的子路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51388823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com