Angular 9 Alert : TypeError: Unable to access property 'routes' as it is undefined

Currently, I am in the process of learning Angular 9 and experimenting with new features. Recently, I decided to explore router-outlets with a name property which is demonstrated in the code snippet below.

This is the template I used:

<router-outlet name='list1'></router-outlet>

This is my router module setup:

    import { NgModule } from "@angular/core";
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard.component';

const dashboardRoutes: Routes = [
    {
        path: "", component: DashboardComponent, children: [
            { path: "", outlet: "list1", data: { msg: "This is ITEMS LIST test1" }, loadChildren: () => import("../items-list/items-list.module").then(m => m.ItemsListModule) },
        ]
    }
];

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

Although everything seems to be working correctly, I encountered an issue when manually reloading the page. My Angular application crashes and displays the following error:

core.js:6260 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'routes' of undefined
TypeError: Cannot read property 'routes' of undefined
    at getChildConfig (router.js:5910)
    at Recognizer.processSegmentAgainstRoute (router.js:5836)
    at Recognizer.processSegment (router.js:5783)
    at Recognizer.processSegmentGroup (router.js:5754)
    at router.js:5768
    at router.js:1917
    at forEach (router.js:1455)
    at mapChildrenIntoArray (router.js:1910)
    at Recognizer.processChildren (router.js:5763)
    at Recognizer.processSegmentAgainstRoute (router.js:5840)
    at resolvePromise (zone-evergreen.js:798)
    at resolvePromise (zone-evergreen.js:750)
    at zone-evergreen.js:860
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:41640)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398)
    at Zone.runTask (zone-evergreen.js:167)
    at drainMicroTaskQueue (zone-evergreen.js:569)

If anyone has experienced this issue before and can offer some assistance, it would be greatly appreciated.

Thank you for your help.

Answer №1

To ensure proper functionality, make sure you are utilizing an additional outlet that does not have a specified name. Within your component, simply include

<router-outlet></router-outlet>
and modify your router module file as shown below:

const dashboardRoutes: Routes = [
    {
        path: "", component: DashboardComponent, loadChildren: () => import("../items-list/items-list.module").then(m => m.ItemsListModule) },
        ]
    }
];

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

The function 'ShouldWorkController' was expected but is not defined, receiving undefined instead

Whenever I attempt to connect a controller to a template using the angular-ui-router $stateProvider, I encounter this error message: 'ShouldWorkController' is not a function. Got undefined. Surprisingly, when I define the controller within the ...

The POST Method is failing to transmit all the necessary data

I recently started a new project using angular, node, express, and postgresql/sequelize. It's been an exciting learning experience, but I've encountered some challenges. Specifically, I'm having trouble setting up an update route for a model ...

Vue.js - Maintaining input value when model declines updates

I am working on a text input that allows users to enter numbers with a maximum of three digits after the decimal point: <v-text-field type="text" :value="num" @change="changeNum($event)" /> <p>{{ num }}</p> ... export default { data: ...

How can one change the data type specified in an interface in TypeScript?

I am currently diving into TypeScript and looking to integrate it into my React Native application. Imagine having a component structured like this: interface Props { name: string; onChangeText: (args: { name: string; value: string }) => void; s ...

Redirecting an autoplaying HTML5 video to full screen upon completion

Although I have seen this question asked before, I am struggling to make it work. I am new to javascript and only have a basic understanding of it. I have a link on my website that directs users to a full-screen video that autoplays, which is working fine ...

Execute a function every 10 seconds after it finishes running (JavaScript)

I am currently facing a challenge with a function that utilizes the "post" method to retrieve data from the server for processing. The amount of data retrieved varies, leading to longer completion times (around 30 seconds). My goal is to have this functi ...

Having trouble getting static serving to work on Express.js when custom middleware is added

Seeking assistance with creating a middleware for my express js website to incorporate subdomains and serve static image, css, and js files. While my HTML pages load properly, I encounter long page load times and the javascript files fail to load. Any gui ...

Using CSS to customize the appearance of the preview in CKEditor

After successfully integrating CKEditor into my website CMS, I am facing an issue with the Preview button not using stylesheets (CSS). Despite editing the preview.html file located in: Website/ckeditor/plugins/preview/ It appears that the CSS is being ig ...

Angular 5 requires the Google Map API call to be made before initiating the http get request

I am experimenting with URL parameters to make a GET request and then use JSON output to drive a query in Google Maps. Currently, I have managed to make the embedded map function by sanitizing it and passing static data. However, when making the query call ...

Mastering Data Transmission: Sending and Receiving Various Data Types Between React and Flask

Looking to send both user image and user data together to create a user on the backend using Flask. Currently, I am sending it as parameters but would like to include everything in the body of a POST request in React. React: const newData = new FormData( ...

What steps can I take to resolve the issue of encountering the error message "Module '@endb/sqlite' not found"?

Currently, I am facing a challenge while attempting to set up a database for my discord bot using node.js with sql/sqlite 3. I have installed the necessary dependencies such as 'endb', sql, and sqlite3 through npm install. However, upon completio ...

Angular Error Handler - Extracting component context information from errors

In the event of a TypeScript error, I am looking to send all of the component's attribute values to a REST API. It would greatly benefit me if I could access the component's context (this) in order to retrieve the values of all attributes within ...

Access a file from an npm module using an executable command

I have a npm module called @jcubic/lips, which includes an executable file. I need to open a file located within the module's directory. This module is installed globally. The specific file I want to access is ../examples/helpers.lips, relative to th ...

I'm seeking some assistance in resolving my JavaScript issue

Let's create a function known as 'bigOrSmall' that requires one parameter, 'arr', which will contain an array of numbers. Inside the 'bigOrSmall' function, let's define a new array named 'answers'. Next, it ...

What provides quicker performance in AngularJS: a directive or one-time binding?

I need to display a static array on a webpage without Angular watching its value. With that requirement in mind, my question is: Which method is faster: using a directive to fetch a scope variable and create an HTML element with this variable as a hard-co ...

Transform a specialized function into a generic function with static typing

First off, I have a network of routes structured like this: interface RouteObject { id: string; path: string; children?: RouteObject[]; } const routeObjects: RouteObject[] = [ { id: 'root', path: '/', children: [ ...

Encountering unresponsive npm behavior post-prefix modification

Recently, I attempted to update my IONIC CLI via npm. The installation was successful multiple times, but the version of CLI remained unchanged. After some research, I decided to modify the npm prefix, which resulted in the IONIC command not being found. F ...

How can I efficiently retrieve the name variable of a Quasar (or Vue 3) application?

Is there a way to incorporate something similar in Quasar without having to redefine the variable in every component? <template> <div>Enjoy your time at {{ APP_NAME }}.</div> </template> During the setup of my app with Quasar C ...

Ways to decrease the space between lines of text within a single mat-option element

https://i.sstatic.net/Sr1cb.png ::ng-deep .mat-select-panel mat-option.mat-option { height: unset; } ::ng-deep .mat-option-text.mat-option-text { white-space: normal; } Currently, I have implemented this code to ensure that text in options wraps to t ...

Is there a way to modify an existing job in Kue Node.js after it has been created?

Utilizing Kue, I am generating employment opportunities. jobs.create('myQueue', { 'title':'test', 'job_id': id ,'params': params } ) .delay(milliseconds) .removeOnComplete( true ) ...