【问题标题】:Lazy Loading Problem : Cannot match any routes. URL Segment延迟加载问题:无法匹配任何路由。网址段
【发布时间】:2021-08-25 13:59:56
【问题描述】:

我正在开发 Angular 11 版本。使用延迟加载。但是在运行应用程序时,它向我显示了一个错误。还有

<a [routerLink]="['/Login']">Login</a>
<a [routerLink]="['/student/Add']">Student</a>

将项目分成两个文件夹 1) Home,这里是home.routing.ts文件代码。


const routes: Routes = [
 
  {path:'Login',component:UserLoginComponent},
  {path:'student',
    loadChildren:()=>import('../Student/Student.module').then(m=>m.StudentModule),
  canActivate:[MyAuthGuard]}
];

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

  1. 学生文件夹,Student.Routing.ts 文件
const Studentroutes: Routes = [

 {path:'Add',component:StudentComponent},

];

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

这里是UserLogin.Component.ts文件按钮点击事件。

  Add(){
    alert(this.stuMNGTObj.name);
    var observable = this.httpClient.post(this.config.apiUrl+"home/Insert",this.stuMNGTObj);
    observable.subscribe(res=>this.Sucess(res),res=>this.Error(res)); 
    alert("Conti"); 
}

【问题讨论】:

  • 它显示的错误是什么?
  • @Sam 无法匹配任何路由。 URL 段:“学生/添加”错误:无法匹配任何路由。 URL 段:'学生/添加
  • 您是否在 StudentModule 中定义了 Router.forChild(),并传入您的功能路由 Studentroutes
  • @Sam 是的,请检查代码...我已经更新了

标签: angular .net-core


【解决方案1】:

您是否将 StudentRoutingModule 添加到 StudentModule 的导入中?

【讨论】:

    猜你喜欢
    • 2020-04-14
    • 2018-03-08
    • 1970-01-01
    • 2017-03-01
    • 2018-09-01
    • 2017-08-10
    • 2019-04-10
    • 2017-11-13
    • 1970-01-01
    相关资源
    最近更新 更多