Error: No routes found in Angular 5

I have developed an Angular 5 app and set up the following routing configuration in app-routing.module.ts file:

import { ControlPanelComponent } from './dashboard/control-panel/control-panel.component';
import { MainComponent } from './dashboard/main/main.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';

const routes: Routes = [
  {path: '', redirectTo: '/dashboard', pathMatch: 'full'},
  {path: 'dashboard', component: DashboardComponent,
    children: [
      {path: '', outlet: 'dashboard-outlet', component: MainComponent},
      {path: 'control', outlet: 'dashboard-outlet', component: ControlPanelComponent}
    ]
  }
];

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

The routing works for the following URLs:
http://localhost:4200
http://localhost:4200/dashboard

However, it does not work for
http://localhost:4200/dashboard/control

When attempting to access 'dashboard/control', I see the following error in the console:

NavigationError(id: 2, url: '/dashboard/control', error: Error: Cannot match any routes. URL Segment: 'dashboard/control')

UPDATE:

The structure of my app is as follows:

  • app
    • dashboard (contains left navigation with router links)
      • main
      • control

This is the left navigation within the dashboard:

<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
          <div class="menu_section">
            <h3>General</h3>
            <ul class="nav side-menu">
              <li><a routerLink="/dashboard" routerLinkActive="active"><i class="fa fa-home"></i>Dashboard</a></li>
              <li><a><i class="fa fa-shield"></i> Options <span class="fa fa-chevron-down"></span></a>
                <ul class="nav child_menu">
                  <li><a [routerLink]="['./control']" routerLinkActive="active">Control Panel</a></li>
                </ul>
              </li>
            </ul>
          </div>
        </div>

The content of the page in the dashboard contains a router-outlet:

<div class="right_col" role="main">
      <div class="">
        <div class="page-title">
          <div class="title_left">
            <h3>{{dashboard.pageTitle}}</h3>
          </div>
        </div>

        <div class="clearfix"></div>

        <router-outlet name="dashboard-outlet"></router-outlet>
      </div>
    </div>

While the link on the dashboard appears correct: http://localhost:4200/dashboard/control

Clicking the link results in no action, and the console displays this error message:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'dashboard/control'

If anyone can provide assistance, it would be greatly appreciated.

Answer №1

Experiment

[routerLink]="['./manipulate']"

This is considered a sub-route of /panel, remember to include a period .

Answer №2

Make sure to add pathMatch: 'full' for the empty path in your nested routes definition.

 children: [
  {path: '', outlet: 'dashboard-outlet', component: MainComponent, pathMatch: 'full'},
  {path: 'control', outlet: 'dashboard-outlet', component: 
    ControlPanelComponent}
  ]
}

Answer №3

In order to address the routing dilemma, I simply inserted the specific outlet in the router link where the page should be displayed:

<li><a [routerLink]="[{ outlets: { 'dashboard-outlet': ['control'] } }]" routerLinkActive="active">Control Panel</a></li>

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

Dealing with numerous errors from various asynchronous pipes in angular - a comprehensive guide

I am facing an issue with 2 mat-select elements in my component, both of which utilize the async pipe: <div class="flex-col"> <mat-label>Issue Desc </mat-label> <mat-form-field> < ...

Acquiring the handle of ngComponentOutlet

I am dynamically creating a component using ngComponentOutlet. Here is an example: import {Component, NgModule} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'alert-success& ...

Following the recent update to webpack-dev-server and webpack, certain modules are being requested that do not exist in the project

Recently, I made updates to my project that involved Vue.js and Typescript. After updating webpack and webpack-dev-server, I encountered a problem where certain modules were missing when attempting to run the project in development mode. Here is some addi ...

Exploring the latest whatwg-fetch update with TypeScript version 2.5.3

Within my TypeScript project, I am currently utilizing "whatwg-fetch": "2.0.3" as the latest version of this polyfill. Additionally, for types, I am using version "@types/whatwg-fetch": "0.0.33", and everything functions smoothly when working with TypeScri ...

Troubleshooting issue in Angular with loading data before rendering the view

Have you ever come across an issue where you navigate to a component and the table appears empty with no data? I noticed that the component/table is displayed, and the data seems to be in the state (session storage) and loaded. I can only see them if I re ...

Managing business logic in an observable callback in Angular with TypeScript - what's the best approach?

Attempting to fetch data and perform a task upon success using an Angular HttpClient call has led me to the following scenario: return this.http.post('api/my-route', model).subscribe( data => ( this.data = data; ...

What is the best way to implement debouncing for an editor value that is controlled by the parent component?

Custom Editor Component import Editor from '@monaco-editor/react'; import { useDebounce } from './useDebounce'; import { useEffect, useState } from 'react'; type Props = { code: string; onChange: (code: string) => void ...

Phaser.js troubleshooting: Overcoming TypeScript errors

I encountered two persistent errors that I have been unable to resolve. While the application runs smoothly in Vite, it fails to transpile due to the mentioned errors outlined below: import Phaser from "phaser"; export default class GameScene ex ...

Angular appears to be unresponsive to callbacks

I currently have a small web application that features a wishlist functionality. While adding items to the list works fine, I am facing an issue with the delete operation in Angular. It seems like Angular does not wait for the response before navigating aw ...

The module 'MatTableModule' could not be located within the '@angular/cdk/table' package during export

Having an issue with using where I'm getting the error message "export 'MatTableModule' was not found in '@angular/cdk/table'. Not sure what I might be doing wrong? You can find more details in my GitHub repository: https://githu ...

Can you explain the purpose of the MomentInput type in ReactJS when using TypeScript?

I am currently facing an issue where I need to distinguish between a moment date input (material-ui-pickers) and a normal text input for an event in my project. const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => { const i ...

Instructions for utilizing ObjectId with a string _id on the client side

Is there a way to retrieve a document using the _id in string format? Here is an example of the code on the client side: 'use client' ... const Page(){ ... fetch("api/get_data", { method: 'POST', ...

What is the process for performing type checking on a block of TypeScript code stored in memory?

I am currently integrating TypeScript support into my project called Data-Forge Notebook. My goal is to compile, perform type checking, and evaluate snippets of TypeScript code within the application. Compiling the code seems straightforward using the tr ...

Struggles with updating app.component.ts in both @angular/router and nativescript-angular/router versions

I have been attempting to update my NativeScript application, and I am facing challenges with the new routing system introduced in the latest Angular upgrade. In my package.json file, my dependency was: "@angular/router": "3.0.0-beta.2" After the upg ...

Ways to incorporate forms.value .dirty into an if statement for an Angular reactive form

I'm a beginner with Angular and I'm working with reactive Angular forms. In my form, I have two password fields and I want to ensure that only one password is updated at a time. If someone tries to edit both Password1 and Password2 input fields s ...

Utilizing Dynamic Class Names in Angular 7 with Typescript

In the process of developing an Angular 7 application, I have created a form component that is intended to be used for various entities. As part of this, I defined a variable route: {path: ':entity/create', component: FormComponent} While this ...

What is the best way to incorporate audio playback while browsing files on an HTML5 webpage with TypeScript?

<input type="file" id="soundUrl" (change)="onAudioPlay()" /> <audio id="sound" controls></audio> This is the HTML code I'm working with, and I'm looking to trigger audio playback after a user selects an MP3 file using TypeScrip ...

Differences Between Angular 2 CoreModule and SharedModule

Can anyone provide an explanation of the purpose of a SharedModule and a CoreModule? I've noticed that many projects are adopting this structure when building their Angular applications. What is the reasoning behind having two separate modules? At ...

Exploring the Functionality of the MatSlideToggleChange Event in the mat-slide-toggle Component

I want to create a form that switches between two dropdown menus using a switch. Is it possible to use the MatSlideToggleChange event from the MatSlide class to make this happen? ...

How to Nest Interfaces in TypeScript

I'm just starting to learn about Angular and I am having trouble getting the interface class to work properly. export interface Header { parentTitles: string; childHeaders: ChildHeader[]; titleIcon: string; url: string; } export interf ...