Angular is unable to find any matching routes for the provided URL segment

I am currently facing an issue with my project. I have a board divided into four columns, each containing n number of items. When I click on an item, the details section in a side nav should be loaded. However, every time I try to open the details section, I encounter the following error message:

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'HyPE4PM/2/details/5413869/DETAILS'
. I have structured my app in such a way that my app.module lazily loads the backlog.module, which in turn lazily loads the board.module as children, and the board.module lazily loads the details.module as children.

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]
})

When trying to navigate to the details of the selected item, I use the router.navigate method:

  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]]);
  }

For a better understanding of the error, I have provided a stackblitz link here. Feel free to check it out and try to navigate to the route hype/2/details to see the error in action.

Answer №1

To add a new path in the board-routing.module, follow this example:

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 {}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In Rxjs, ConcatMap doesn't get executed

I am currently developing a file upload component that involves checking for the existence of a file before proceeding with the upload process. If the file already exists, the user is given the option to either save as a copy or overwrite the existing file ...

TypeScript's type inference feature functions well in scenario one but encounters an error in a different situation

I recently tried out TypeScript's type inference feature, where we don't specify variable types like number, string, or boolean and let TypeScript figure it out during initialization or assignment. However, I encountered some confusion in its be ...

Is there a way to retrieve a particular object from a versatile function?

Here is a generic function to consider: public getData<T>(url: string): Observable<T> { return this.httpClient.get<T>(url); } I am looking for a way to test this function by returning a mock object array, especially if the remote ...

Retrieving the name of the current page in ionViewCanEnter

While working with Ionic 2, I am currently facing a challenge in identifying the name of the page that triggered the navigation (PUSHER) before entering the destination page (PUSHEE). Within the PUSHEE page, I have an ionViewCanEnter function where I need ...

Difficulty with setting up Typescript in Visual Studio Code on MacOS Catalina

I'm currently facing an issue that appears to be related to the environment. How can I resolve it? And how do I link the installed TSC to my console? Steps to Recreate: npm install -g typescript was able to successfully install or update [email ...

Can the return type of a function be determined dynamically at runtime by analyzing a function parameter value?

Let's delve into this concept with an illustrative example! interface Query { foo: any; } interface Mutation { bar: any; } type OperationName = keyof Query | keyof Mutation; const request = async <T>(args, operationName: OperationName): P ...

Refreshing DataTables with specific parameters using ajax.reload()

In my Angular2 project, I am utilizing DataTables with the serverSide feature. After making changes, I am attempting to reload the table and pass these changes as parameters in a POST request via AJAX. The issue I am encountering is that DataTables alway ...

My Angular2 pipe is not working as expected

I have developed a custom pipe to search through a table based on ID. Below is the example JSON data that I am utilizing to populate the tables: [ { "id": "59247cd5a05cfa4966af706d", "lease": { "client": { "client_id": 1, ...

What is the best way to postpone resolving a dependency within the injector?

I want to dynamically configure the injector when ngOnInit is triggered. Here's my approach: <my-component [config]="someConfig"></my-component> // my.component.ts import { CONFIG_TOKEN } from 'injector_tokens'; @Co ...

Changing the generic type's constraint type in TypeScript to have more flexibility

I have developed a utility type named DataType that takes in a parameter T restricted to the type keyof MyObject. When the key exists in MyObject, DataType will return the property type from MyObject; otherwise, it will simply return T. interface MyObject ...

Explore one of the elements within a tuple

Can we simplify mapping a tuple element in TypeScript? I'm seeking an elegant way to abstract the following task const arr: [string, string][] = [['a', 'b'], ['c', 'd'], ['e', 'f']] const f ...

Utilize a module within a script in the continuous integration setup of a React application

I've created a module to verify if all the necessary environment variables are properly set in a React application. Here's a simple example of how it works: const getEnvironmentVariable = (key: string): string => { if (process.env[key]) { ...

Adding *ngIf dynamically within a directive allows for conditional rendering based on certain parameters or

Is there a way to dynamically include an *ngIf on an element that is decorated with an attribute directive? I decided to test this with a simple experiment: @Directive({ selector: '[lhUserHasRights]' }) export class UserHasRightsDirective i ...

having difficulty with installing the bootstrap framework

I'm having issues installing the ng-bootstrap in my project. I keep encountering the following error message. Despite trying to execute the commands below, I haven't had any success. npm install --legacy-peer-deps npm install latest-version He ...

The publish-subscribe feature appears to be ineffective

Recently starting with meteor, I learned about the importance of removing autopublish. So, I decided to publish and subscribe to a collection in order to retrieve two different sets of values. Here is the code on my meteor side: Meteor.publish('chann ...

Unable to compile TypeScript files using gulp while targeting ES5

After starting my first Angular2 app, I encountered an issue where I couldn't use gulp to compile for es5. Below is the dependencies file: "dependencies": { "@angular/common": "2.0.0", "@angular/compiler": "2.0.0", "@angular/compiler-cli ...

Implementing child components rendering in a React application using TypeScript

Just a little background information: I am attempting to build a carousel with pagination using ReactJS. Here is the code snippet I currently have: interface HTMLCarouselT { children: Array<JSX.Element> size: number; } const HTMLCarousel = ({ch ...

Master the Art of Crafting Unique URLs

I am developing a web page that requires me to call two queries, each requiring an ID. However, I'm unsure of the best way to pass these IDs in the URL. For instance, one query is for books and the other is for authors. Currently, I have considered tw ...

Customize the element of the root node of a MUI component using the styled()

I am trying to implement the "component" prop with a MUI component (such as ListItem) using the styled() API. However, I am facing an issue where it says that "component" is not a valid prop. Can someone guide me on how to correctly achieve this? I have se ...

Is there a way for me to access the user's gender and birthday following their login using their Google account details?

I have successfully implemented a Google sign-in button in my Angular application following the example provided in Display the Sign In With Google button: <div id="g_id_onload" class="mt-3" data-client_id="XXXXXXXXXXXX-XX ...