Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法在应用程序模块内创建的子模块中实现路由_Angular_Angular Routing_Angular Module - Fatal编程技术网

Angular 无法在应用程序模块内创建的子模块中实现路由

Angular 无法在应用程序模块内创建的子模块中实现路由,angular,angular-routing,angular-module,Angular,Angular Routing,Angular Module,除了在应用程序模块中创建的路由模块之外,我正在尝试在子模块中实现路由 我在应用程序模块中创建了三个子模块,即登录、主页和管理模块,并在应用程序文件夹中创建了一个主路由模块,用于在登录、主页和管理子模块之间导航 我还在home模块中创建了三个组件,即HomeComponent、CreateAlertsComponent和UpdateAlertsComponent,以及名为routeHome.module.ts的路由模块,用于在home组件之间导航 我可以使用routing-module.ts在子模

除了在应用程序模块中创建的路由模块之外,我正在尝试在子模块中实现路由

我在应用程序模块中创建了三个子模块,即登录、主页和管理模块,并在应用程序文件夹中创建了一个主路由模块,用于在登录、主页和管理子模块之间导航

我还在home模块中创建了三个组件,即HomeComponent、CreateAlertsComponent和UpdateAlertsComponent,以及名为routeHome.module.ts的路由模块,用于在home组件之间导航

我可以使用routing-module.ts在子模块之间布线,但无法在主模块中创建的组件之间布线

我得到的错误如下所示

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'Home/home/Alerts/create-alerts'
Error: Cannot match any routes. URL Segment: 'Home/home/Alerts/create-alerts'
    at ApplyRedirects.noMatchError (router.js:1765)
    at CatchSubscriber.eval [as selector] (router.js:1730)
    at CatchSubscriber.error (catchError.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at LastSubscriber.Subscriber._error (Subscriber.js:134)
    at ApplyRedirects.noMatchError (router.js:1765)
    at CatchSubscriber.eval [as selector] (router.js:1730)
    at CatchSubscriber.error (catchError.js:105)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at MapSubscriber.Subscriber._error (Subscriber.js:134)
    at MapSubscriber.Subscriber.error (Subscriber.js:108)
    at LastSubscriber.Subscriber._error (Subscriber.js:134)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at eval (zone.js:873)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4751)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.invokeTask [as invoke] (zone.js:500)
    at invokeTask (zone.js:1540)
下面显示的是我的目录结构和创建的子模块admin、home和login

下面显示的是我的目录结构,其中包含home子模块中的组件和routeHome.module.ts

请在上访问我的代码


任何人都可以帮助解决此路由冲突吗?

您可以使用子路由在应用程序中导航:

{
  path:'Home/home',
  component: HomeComponent,
  children: [
    {
      path: 'Alerts/create-alerts',
      component: CreateAlertsComponent,
    },
  ],
},
您还可以查看以查看更多示例


编辑:还可以添加到home.component.html文件以呈现子组件。

您可以使用子路由在应用程序中导航:

{
  path:'Home/home',
  component: HomeComponent,
  children: [
    {
      path: 'Alerts/create-alerts',
      component: CreateAlertsComponent,
    },
  ],
},
您还可以查看以查看更多示例


编辑:还可以添加到home.component.html文件以呈现子组件。

因为您已将应用程序拆分为模块。我建议你使用。在您的情况下,HomeModule的功能模块必须连接到RoutingModule,以便路由器了解它

更新了你的代码

在RoutingModule中,使用以下内容更新routes阵列:

const routes: Routes = [
  { path:'Login/login', component: LoginComponent },
  { path:'Home', loadChildren: "./home/home.module#HomeModule" },
  { path:'Admin/admin', component: AdminComponent },
];
请注意,延迟加载语法使用loadChildren,后跟一个字符串(模块路径)、一个哈希标记或,以及模块的类名

通过将RouteHomeModule更新为以下内容来配置HomeModule路由:

请注意,延迟加载的模块应该使用RouterModule.forChild而不是RouterModule.forRoot

最后,从AppModule声明中删除HomeComponent、CreateAlertsComponent和UpdateAlertsComponent,因为这些组件是app.component.html中HomeModule和update routerLink的一部分。在AppModule中:

app.component.html:


因为你已经把你的应用分成了几个模块。我建议你使用。在您的情况下,HomeModule的功能模块必须连接到RoutingModule,以便路由器了解它

更新了你的代码

在RoutingModule中,使用以下内容更新routes阵列:

const routes: Routes = [
  { path:'Login/login', component: LoginComponent },
  { path:'Home', loadChildren: "./home/home.module#HomeModule" },
  { path:'Admin/admin', component: AdminComponent },
];
请注意,延迟加载语法使用loadChildren,后跟一个字符串(模块路径)、一个哈希标记或,以及模块的类名

通过将RouteHomeModule更新为以下内容来配置HomeModule路由:

请注意,延迟加载的模块应该使用RouterModule.forChild而不是RouterModule.forRoot

最后,从AppModule声明中删除HomeComponent、CreateAlertsComponent和UpdateAlertsComponent,因为这些组件是app.component.html中HomeModule和update routerLink的一部分。在AppModule中:

app.component.html:


但我还是得到了与上述问题相同的错误。。。。。错误:无法匹配任何路由。URL段:'Home/Home/Alerts/create-Alerts',但我仍然得到了与上述问题相同的错误。。。。。错误:无法匹配任何路由。URL段:“主页/主页/提醒/创建提醒”也感谢您为我的网站花费宝贵的时间question@Heena很乐意帮忙你能帮我解决这个问题吗。?也谢谢你为我的生日花了宝贵的时间question@Heena很乐意帮忙你能帮我解决这个问题吗。?
<button mat-raised-button
  routerLink='Home' 
  routerLinkActive="active">
  Home
</button>