首页 > 解决方案 > Angular 的子路由不能工作

问题描述

有人可以帮助我吗,我被困在 6 条儿童路线中。我的角度子路由无法在延迟负载下工作。

这是我的应用程序路由模块

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


const routes: Routes = [
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
  {
    path: 'master',
    loadChildren: './modules/master/master.module#MasterModule'
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    // preload all modules; optionally we could
    // implement a custom preloading strategy for just some
    // of the modules (PRs welcome )
    preloadingStrategy: PreloadAllModules
  })],
  exports: [ RouterModule ]
})

export class AppRoutingModule { }

然后,这是我的主路由模块

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

import { DokterComponent } from './dokter/dokter.component';
import { MasterComponent } from './master.component';

const routes: Routes = [  
  {
    path: '',
    component: MasterComponent
    children: [
      { path: "", component: DokterComponent, pathMatch: "full" },
    ]
  }
];

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

当我尝试访问/master/dokter 时,没有错误消息,但无法加载dokterComponent。感谢您的关注。

标签: angular

解决方案


推荐阅读