Encountering a problem with lazy loading of module routing paths. Issue arises when attempting to navigate to http://localhost:4200

AppLazyLoadingMoudle

import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';

const ROUTES : Routes = [
    /*
        ProductModule (defined in the feature module) is loaded lazily when navigating to /products
    */
   {path: '', component: AppComponent},
   {path : 'products', loadChildren : () => import('./product/product.module').then(m => m.ProductModule) }

];

@NgModule({
    imports : [RouterModule.forRoot(ROUTES, {enableTracing: true})],
    exports: [RouterModule]
})

export class AppLazyLoadingMoudle {}

MainAppModule

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {HttpClientModule} from "@angular/common/http";
import {RouterModule, Routes} from '@angular/router';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {CommonHttpService} from './http-services/common-http.service';
import { ProductModule } from './product/product.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
   
   // ProductModule
  ],
  providers: [CommonHttpService], 
  bootstrap: [AppComponent]
})
export class MainAppModule { }

ProductFeatureRoutingModule

import { RouterModule ,Routes} from '@angular/router';
import {NgModule} from '@angular/core';
import { ProductComponent } from './product.component';
import { ProductItemComponent } from './product-item/product-item.component';


const ROUTES : Routes = [
    {path: '', component: ProductComponent},
    {path: ':id', component: ProductItemComponent}
];

@NgModule({
    imports : [RouterModule.forChild(ROUTES)],
    exports: [RouterModule]
})

export class ProductFeatureRoutingModule{}

ProductFeatureModule

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';


import { ProductItemComponent } from './product-item/product-item.component';
import { ProductComponent } from './product.component';
import {CommonHttpService} from '../http-services/common-http.service';
import { ProductFeatureRoutingModule } from './product.routing.module';

@NgModule({
  declarations: [
    ProductComponent,
    ProductItemComponent
  ],
  imports: [
    CommonModule,
    ProductFeatureRoutingModule
  ],
  providers : [CommonHttpService] 
})
export class ProductFeatureModule { }

app.component.html

<!-- Toolbar -->
<div class="toolbar" role="banner">
  <span>Welcome</span>
</div>

<div class="content" role="main">
  <!-- Highlight Card -->
  <div class="card highlight-card card-small">
    <span>{{ title }} app is running!</span>
  </div>

  <div class="card-container">
  </div>
  <div class="card-container">
  </div>
  <!-- Terminal -->
  <div class="terminal" >
  </div>
  <!-- Links -->
  <div class="card-container">
  </div>
  <!-- Footer -->
  <footer>
      Love Angular?
  </footer>
</div>

<router-outlet></router-outlet>

Error: main.ts:6 ERROR Error: Uncaught (in promise): Error: NG04002: Cannot match any routes. URL Segment: 'products' Error: NG04002: Cannot match any routes. URL Segment: 'products' at Recognizer.noMatchError (router.mjs:3655:16)


Versions:

  • Angular CLI: 16.2.0 Node: 16.18.0 Package Manager: npm 8.19.2

Angular: 16.2.0 animations, cli, common, compiler, compiler-cli, core, forms platform-browser, platform-browser-dynamic, router

Package Version
@angular-devkit/architect 0.1602.0
@angular-devkit/build-angular 16.2.0
@angular-devkit/core 16.2.0
@angular-devkit/schematics 16.2.0
@schematics/angular 16.2.0
rxjs 7.8.1
typescript 5.1.6
zone.js 0.13.1

I am attempting to access ProductComponent from ProductFeatureModule using lazy loading technique from the root module(MainAppModule) with a separate routing module AppRoutingModule for better organization of code.

The products route loads successfully if I directly import the product into MainAppModule but fails when implementing lazy loading route concepts. I am uncertain as to why this is not functioning and what exactly am I overlooking?

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

Uploading Files Using the Dropbox API Version 2

Before, I integrated the Dropbox API V1 into my web application to upload files to my personal Dropbox account. The app was configured to use only one specific dropbox account for file uploads. Previous Process: I registered an app on the dropbox develo ...

`How to Merge Angular Route Parameters?`

In the Angular Material Docs application, path parameters are combined in the following manner: // Combine params from all of the path into a single object. this.params = combineLatest( this._route.pathFromRoot.map(route => route.params) ...

Displaying the information fetched using axios on the screen using node.js

Is there a way to display the information from the input boxes in the image on the screen using node js? ...

The conversion of string to number is not getting displayed correctly when using console.log or document.write. Additionally, the concatenated display is also not functioning as intended

Being new to JS and HTML, this program was created to enhance my understanding of the concepts. I attempted a basic program to convert a string to a number in three different ways, but I am having trouble determining if the conversion actually took place. ...

Error: Incorrect Path for Dynamic Import

Recently, I've been trying to dynamically load locale files based on the locale code provided by Next.js. Unfortunately, every time I attempt a dynamic import, an error surfaces and it seems like the import path is incorrect: Unable to load translatio ...

The submit button remains disabled even after verifying all the required fields

I have a registration form with basic customer details and a Submit button. I have successfully validated all the fields using Ajax, except for the Confirm password field which is being validated using JavaScript. The issue I am facing is that when I val ...

What is causing the error message 'undefined is not a function' to appear in my code?

Struggling to send a file in response to a GET request with express.js. I created a basic FileManager class to manage file requests, yet encountering an error of 'undefined is not a function' when calling new FileManager() Here's my approac ...

Angular JS: Distribute objects from a single array to various arrays or services

I have recently embarked on developing a basic app using Angular JS, utilizing a service/factory to manage data and enable the addition of objects. Within the array of various individuals (listed in the html), you can include them as candidates by employi ...

Incorporate JavaScript code into an Angular UI-Router view

I can't seem to find an answer to this question anywhere, so I'm hoping someone here can help me out. In my AngularJS app, I am using ui-router to load multiple views into the same <ui-view> element. I am trying to implement Jquery UI&apos ...

Performing a conditional query on a Many-to-Many relationship in TypeORM

Operating under a many-to-many relationship between Category and Product entities In need of filtering products based on category ID Attempted to implement the following code after referring to some examples, but encountered difficulties in making it fun ...

What is the best method for incorporating a JavaScript redirect into an Android WebView?

My issue involves loading a page into a webview. Typically, when I use the code webview.loadUrl(url); it functions as expected. The url contains a javascript code that redirects the page. Here is the javascript code: <script type="text/javascript"> ...

Solution to trigger CSS :hover to refresh following a transition (such as expanding a menu)

While there are existing discussions on this topic, I am presenting my query for two specific reasons: It introduces a potential alternative solution The demo code could be helpful to individuals looking to emulate a menu Following a CSS transition, the ...

The reliability of next router events can sometimes be called into question as they do not always function consistently

I've been working on creating a loading screen for my Next.js project. The issue I'm facing is that sometimes the loading message stays on the screen and doesn't go away even after the page has loaded. I suspect this may be due to the state ...

The significance of the "? :" operator in JavaScript

These are the lines of code I am currently working with: toggleMore : function( $item, show ) { ( show ) ? $item.find('a.ca-more').show() : $item.find('a.ca-more').hide(); }, Could someone help me understand what this code does? ...

Pagination in Laravel using Angular 5

Currently experiencing pagination issues in an Angular5 and Laravel5 project. The JSON values are as follows: { "products": { "current_page": 1, "data": [ ... ], "first_page_url": "http://localhost:8000/api/ ...

The Angular 8 HTTP patch request is successfully completed, however, it is not returning the expected response on

In Angular 8, I have a function in a service with an http patch call: // public returnStr: string = ""; at top of service updateResponse(response: Response, reviewId: number): string { this.http.patch(`/assessing/api/reviews/update/${review ...

What could be causing this error to appear when using Next.js middleware?

The Issue at Hand Currently, I am in the process of setting up an authentication system using Next.js, Prisma, and NextAuth's Email Provider strategy. My goal is to implement Next.js middleware to redirect any requests that do not have a valid sessio ...

Retrieving data from a radgrid with the power of jQuery

Trying to extract the text from the label GetName in a radgrid using jQuery. Need to iterate through each record to check the value of the label. Can anyone provide assistance? Thanks! Below is the code for my radgrid. <telerik:RadGrid ID="Gridview1 ...

What is the best way to reference a JavaScript or jQuery variable within a PHP variable?

Is it possible to read a javascript or jquery variable through php code? For example: <script> var num = 3; </script> <php? $a = 20; $b = num*$a; // Is this valid? ?> Any thoughts on this? ...

The ngIf statement in the template isn't functioning properly after a refresh; instead, it is causing a redirection to the homepage

I've been developing with Angular 7, trying to display a <div> ... </div> based on multiple values that I declared as : Boolean = false; in the .ts file. These values are updated in ngOnInit, but for some reason, the page keeps redirecting ...