Modules can cause issues with Angular routing functionality

I am working on a management system that consists of multiple modules.

The starting point for the application is the login-module. Upon successful login, the user is redirected to the main-module. From the main-module, users can navigate to other modules such as inventory and customers.

However, when changing the route from http://localhost:4200/dashboard to http://localhost:4200/customers, the customers module does not load. It works fine when I route to

http://localhost:4200/customers/customers
.

                                           AppModule
                                           /       \
                                          /         \
                                 login-module  -->  main-module
                                                      /      \
                                                     /        \
                                        dashboard-module      customers-module

I'm unsure about what I might be doing wrong in this scenario.

Below are some relevant code snippets:

  1. app-component.html

    <router-outlet></router-outlet>

  2. app-routing.module.ts

import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from './guards/AuthGuard/auth.guard';

const routes: Routes = [
 {
   path: "",
   redirectTo: '/dashboard',
   pathMatch: "full"
 },
 {
   path: "dashboard",
   loadChildren: () => import('./modules/main/main.module').then(m => m.MainModule)
 },
 {
   path: "customers",
   loadChildren: () => import('./modules/main/main.module').then(m => m.MainModule)
 },
 {
   path: 'login',
   loadChildren: () => import('./modules/login/login.module').then(m => m.LoginModule),
 },

];

@NgModule({
 imports: [RouterModule.forRoot(routes)],
 exports: [RouterModule]
})
export class AppRoutingModule { }
  1. main-routing.module.ts
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from 'src/app/guards/AuthGuard/auth.guard';
import { MainComponent } from './components/main/main.component';

const routes: Routes = [
  {
    path: '',
    component: MainComponent,
    loadChildren: () => import('../dashboard/dashboard.module').then(m => m.DashboardModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'dashboard',
    component: MainComponent,
    loadChildren: () => import('../dashboard/dashboard.module').then(m => m.DashboardModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'customers',
    component: MainComponent,
    loadChildren: () => import('../customers/customers.module').then(m => m.CustomersModule),
    canActivate: [AuthGuard]
  },
];

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

  1. main.component.html
<div class="wrapper default-theme" [ngClass]="getClasses()">
    <app-navbar></app-navbar>
    <main>
      <app-sidebar></app-sidebar>
      <div class="pages container-fluid pt-4 pb-4 pl-4 pr-4">
        <router-outlet></router-outlet>
        <hr>
        <app-footer></app-footer>
      </div>
      <div class="overlay" (click)="toggleSidebar()"></div>
    </main>
  </div>

Answer №1

http://localhost:4200/customers/cutomers

The word 'customers' has been misspelled in this instance

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

Issue with Angular 8 - Material Table displaying incorrect data after deletion操作

I'm working on a material table that showcases different options through selects. My main object is the ngModel, which holds all the available options. These options are fetched from a database. Let's say I have a root item called menu, which m ...

Implement conditional props for a React component by linking them to existing props

In my current project, I am working on a component that has a loading state. The component has an isLoading prop which determines whether the component is currently in a loading state or not: interface CustomImageComponentProps { isLoading: boolean ...

Best practices for stubbing an element in order to effectively unit test a LitElement component

Trying to perform unit tests on LitElement components has been quite a challenge for me. I found myself stuck when attempting to isolate components, particularly in figuring out how to stub elements effectively. The Polymer project provides some informatio ...

What is the best way to initiate an Ajax request [POST] from Angular 2 to PHP?

I've hit a roadblock while trying to solve a complex problem, putting in my best effort to find solutions through documentation and searching for similar questions. Although I consulted the documentation at https://angular.io/docs/ts/latest/guide/ser ...

The attribute 'close' is not present in the 'Application' data type

My approach to importing expressjs looks like this: import { Request, Response, Application, Router } from 'express'; const app: Application = require('express')(); In my typings.json file: "express": "registry:npm/express#4.14.0+20 ...

Can classes from an external package be imported into an Angular library within an Angular app using Openlayers?

I am currently developing an Angular library that configures an OpenLayers map as an Angular component. The component is functioning properly, but I need to access classes and constants from a package imported by the library, specifically OpenLayers. To w ...

Discover the power of working with asynchronous values in objects using the latest @if syntax in Angular 17

Previously, we were able to chain multiple async operations using *ngIf directives in Angular. This allowed us to avoid repeating the async pipe in the template and instead reuse them as a single subscription. With the introduction of the new @if syntax in ...

What causes TypeScript to flag spread arguments within callback wrappers?

My aim is to enhance a callback function in TypeScript by wrapping it with additional logic. In order to achieve this, I have an interface called Callbacks that outlines various callback signatures. The objective is to create a wrapper function that can lo ...

Webpacker/Typescript is unable to locate a file within the Rails asset pipeline

I'm currently experiencing difficulty importing a file from the rails asset pipeline as webpack seems to be unable to locate it. Here is the content of my tsconfig.json: { "compilerOptions": { "declaration": false, "emitDecoratorMetadata": ...

Using JavaScript to dynamically calculate the sum of selected column values in Angular Datatables

I have a table set up where, if a checkbox is checked, the amounts are automatically summed and displayed at the top. However, I am encountering issues with the code below as it is not providing the exact sum values. Can anyone suggest a solution to this p ...

Get the data property from the interface and define the return type

In my function, I am trying to extract data from an object structured by an interface. I want this function to specifically resolve the property data from the data object. While it works when I have any as the return type, I believe there should be a more ...

Refreshing a component without having to reload the entire page in Angular4: A step-by-step guide

I have an application built with Angular 4 that consists of two components - one for adding items and another for viewing them. I am facing an issue where the view page does not update with the new item added. Although I can see the updated data source, th ...

Merge two RxJS Observables/Subscriptions and loop through their data

Working with Angular (Version 7) and RxJS, I am making two API calls which return observables that I subscribe to. Now, the challenge is combining these subscriptions as the data from both observables are interdependent. This is necessary to implement cer ...

Looking for a specific string within all attributes of an object using Angular 2

How can I search for a specific string in all properties of an object using Angular 2 with TypeScript? I have a table displaying an array of customers and I want to implement a search feature where the user can input a value and find a customer that match ...

Tips for organizing a multi-dimensional array based on various column indexes

I am looking to organize a multidimensional array by multiple column index. Take, for instance, the test data provided below: var source = [ ["Jack","A","B1", 4], ["AVicky","M", "B2", 2], [ ...

Slow auto page refresh in local development for Angular2 on Windows can be quite frustrating

Recently diving into angular2 and following the heros tutorial from docs. Struggling with a sluggish development experience while working with angular2. It's taking approximately 5 seconds for angular2 to recognize changes in files, followed by anothe ...

What is the correct way to format React's dispatch function in order to utilize a "then" method similar to a Promise?

I'm working on a simple app that dispatches an action upon first load to populate the store. However, I'm facing an issue with trying to run a then method on dispatch, as typescript is throwing errors. (As per redux's documentation, the ret ...

Using TypeScript, implement a function that is called when a React checkbox's state changes to true

Currently, I am experimenting with the react feature called onChange. My goal is to update local data by adding a value when a checkbox is selected. Conversely, when the checkbox is unselected, I just want to display the original data. However, I find that ...

Is a package I overlooked? The 'findOne' property is not found within the 'Schema<Document<any, {}>, Model<any, any>, undefined>'

I have taken over the responsibility of maintaining the websites at my company, and I am encountering the error message (Property 'findOne' does not exist on type 'Schema<Document<any, {}>, Model<any, any>, undefined>' ...

The 'items' property cannot be linked to 'virtual-scroller' as it is not a recognized attribute

I'm currently facing an issue with integrating virtual scroll into my Ionic 4 + Angular project. Previously, I relied on Ionic's implementation of virtual scroll (ion-virtual-scroll) which worked well initially. However, I encountered a major dr ...