Angular无法匹配任何路由。网址段

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

我有一个具有四列的板,每列填充有n个项目,当我单击其中一个项目时,应该加载sidenav中的详细信息部分,由于某些原因,我仍然可以知道为什么...每次我尝试在项目中打开详细信息部分时,都会收到此错误Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'HyPE4PM/2/details/5413869/DETAILS'。现在,我的app.module是延迟加载backlog.module,而我的待办事项模块是将延迟加载board.module作为子级,而board.module则延迟加载details.module作为子级。

app-routing.module

export const routes: Routes = [
  {
    path: 'HyPE4PM',
    loadChildren: () => import('./modules/lazy/backlog.module').then((mod) => mod.BacklogModule)
  },
  {
    path: 'Error',
    loadChildren: () => import('./modules/lazy/error-site.module').then((mod) => mod.ErrorSiteModule)
  }
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: []
})

backlog-routing.module

/**
 * define the routes for the BacklogComponent module
 */
const routes: Routes = [
  {
    path: '',
    component: BacklogComponent,
    children: [
      {
        path: '2',
        loadChildren: () => import('../lazy/boards-modules/taskboard.module').then((mod) => mod.TaskboardModule)
      },
    ]
  }
];

/**
 * define the routing for the BacklogComponent module
 */
@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})

board-routing.module

const routes: Routes = [
  {
    path: '',
    component: TaksboardComponent,
    children: [
      { path: 'details/:id', redirectTo: 'details/:id/DETAILS', pathMatch: 'full' },
      {
        path: 'details/:id/:detailsSection',
        loadChildren: () => import('../lazy/backlog-item-details.module').then((mod) => mod.BacklogItemDetailsModule),
        outlet: 'rightSidenav',
        data: { preload: true, delay: 2500 }
      }
    ]
  }
];

/**
 * define the routing for the BacklogComponent module
 */
@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})

然后我使用router.navigate进入所选项目的详细信息:

  public selectItem(event: MouseEvent, position: DetailSections) {
    this.log.trace(`selectItem() in backlog item comp. id: ${this.backlogItem.id}`);
    this.eventService.hideBoardCreator.emit();
    // as the click to these events are bound on the DOM on childs of the click to the details -> we need to stop the event here
    // if TS on other card is shown, it needs to be hidden
    event.stopPropagation();

    // save selection into store
    this.store.dispatch(new BacklogItemSelected(this.backlogItem));

    // show the details section
    this.router.navigate([`/HyPE4PM/${this.configService.boardtype}/details`, this.backlogItem.id, DetailSections[position]]);
  }

在这里我共享错误的stackblitz ,如您在示例中看到的,如果尝试去hype/2/details路线,则会出错。

angular typescript lazy-loading
2个回答
0
投票

在您的应用程序路由模块中

const routes: Routes = [
  {
    path: 'customers',
    loadChildren: 'src/app/customers/customers.module#CustomersModule'
  },
  {
    path: 'orders',
    loadChildren: 'src/app/orders/orders.module#OrdersModule'
  },
  {
    path: '',
    redirectTo: '',
    pathMatch: 'full'
  }
];

这里是如何使用lazy loading的基本示例


0
投票
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BoardComponent } from './board.component';

/**
    * Define all available routes
*/
export const routes: Routes = [
{
    path: '',
    component: BoardComponent,
    children: [
   {
      path: 'details',
      loadChildren: () => import('./details/details.module').then((mod) => mod.DetailsModule),
    outlet: 'details'
  }
]
},{
    path: 'details',
loadChildren: () => import('./details/details.module').then((mod) => mod.DetailsModule)
 }
];
@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
  providers: []
})
export class BoardRoutingModule {}
© www.soinside.com 2019 - 2024. All rights reserved.