The exploration of child routes and modules

I'm currently working on a somewhat large project and I've decided to break it down into modules. However, I'm facing an issue with accessing the routes of admin.module.ts. In my app.module, I have imported the admin Module.

imports: [
  BrowserModule,
  CommonModule,
  AppRoutingModule,
  FormsModule,
  ReactiveFormsModule,
  HttpModule,
  NgSelectModule,
  AdminModule,
  SharedModule
],

The routing module does not include the admin route in my admin.module.ts. The ngModule in admin.module appears as follows:

@NgModule({
  declarations: [
      AdminComponent,
      AdminLandingComponent
  ], imports: [
      CommonModule,
      AdminRoutingModule
  ]
})

The routes in the admin-routing.module.ts are structured like this:

{ path: 'admin', component: AdminComponent, children: [
  { path: '', component: AdminLandingComponent }
]}

Although I am using forChild(), when attempting to access localhost:4200/admin, I get redirected to a page not found error. What could be causing this issue and how can it be resolved?

Full Files

  1. Parent Module - app module
  2. Main Routes - app-routing module
  3. Submodule - admin module
  4. Child Routes - admin-routing module

Answer №1

@MaksymShevchenko Appreciate your help!
I resolved the issue by including the path:

{path: 'admin', loadChildren: '../admin/admin.module#AdminModule'}

in app-routing.module.ts and updating the path in admin-routing.modules.ts to:
{path: '', component: AdminComponent, children: [
        {path: '', component:AdminLandingComponent}
    ]}

and it worked like a charm.

Alternative solution to tackle the problem

Since I added the module in the imports array, Angular appends the routes after the wildcard route. A different approach is exporting the wildcard route to another module and placing it at the end of all other modules in the root module. This way avoids complicating things with lazy loading.

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 assignment of Type Program[] to a string[] is not valid

I am working with a class that contains information about different programs. My goal is to filter out the active and inactive programs, and then retrieve the names of those programs as an array of strings. Below is the structure of the Program class: ex ...

Encountering a hiccup while trying to install Svelte, Skeleton, and Tail

Recently entering the world of Svelte and TypeScript, I have encountered some unexpected errors after installation. Despite following the same steps as before, I am puzzled by what is causing these issues. This is the process I followed: npm create svelte ...

Is there a way to merge my local store with Firestore using ngrx entity?

Currently, I'm facing a challenge while using NgRx and Firestore as I attempt to keep the local store in sync with a firestore collection. I have set up an observable that triggers when the firestore collection is updated. However, in my reducer, I am ...

What is the proper syntax for using .focus() with the nextElementSibling method in typing?

As I strive to programmatically shift focus in my form using nextElementSibling, I encounter a challenge with typing variables/constants due to working with Typescript... I have managed to achieve success without typing by implementing the following: myF ...

Tips on preventing image previews from consuming too much text data while updating a database in Angular 12 using Material UI for image uploads within a FormGroup object

Currently working with Angular 12 and Angular Material for image uploads with preview. I have a formgroup object below, but I'm running into issues with the 197kb image preview text being inserted into the database. Despite trying setValue/patchValue/ ...

Issue with Angular 4 Bootstrap Carousel

I encountered a console error that I couldn't resolve while working on my project. The technology stack involves Angular 4 and Bootstrap. Unfortunately, my frontend developer is unavailable this weekend, and I'm unsure if there are any missing d ...

Error Encountered: Angular 2 ngOnInit Method Being Executed Twice

Encountered an unusual error in Angular 2 while working on two components that share similarities in templates and services. Here is a breakdown of how they function: Component: data: any; constructor(private _service: TheService) {} ngOnInit() { t ...

Using TypeScript to work with asynchronous child_process.exec operations

Having trouble implementing a child_process.exec call with TypeScript and finding error handling to be quite challenging. Here's the basic idea of what I'm attempting: import { promisify } from "util"; import { exec, ExecException } fr ...

Angular's GET HTTP request has resulted in a 500 error message, specifically the Internal Server Error

Attempting to send a GET request to the server where only authenticated users can access a specific route ("/user") after logging in. However, even after a successful login, users are unable to gain access to the "/user" route. A middleware function named ...

What is the best way to create two MUI accordions stacked on top of each other to each occupy 50% of the parent container, with only their contents scrolling

I am looking to create a layout with two React MUI Accordions stacked vertically in a div. Each accordion should expand independently, taking up the available space while leaving the other's label untouched. When both are expanded, they should collect ...

One important rule to remember when using React Hooks is that they must be called consistently and in the correct order in each render of the component. It

Encountering an issue while trying to use the ternary operator to determine which React Hook to utilize. The error message states: "React Hook "useIsolationDynamicPhase" is called conditionally. React Hooks must be invoked in the same order during every co ...

Expand the initial expansion panel within an Angular Material accordion by opening the first attachment

In Angular Material expansion panels, the expanded input can be used to automatically open a specific panel when the page loads. However, in my dynamic accordion where all panels are optional, I want the first panel to be opened by default. I could manual ...

Encountering a problem when utilizing window.ethereum in Next Js paired with ether JS

Experiencing some difficulties while utilizing the window.ethereum in the latest version of NextJs. Everything was functioning smoothly with NextJs 12, but after upgrading to NextJs 13, this error started popping up. Are there any alternative solutions ava ...

"Trouble with Angular reactive form submission - selected options not being passed through

I have a form that is dynamically populated with multiple select inputs: <form [formGroup]="searchForm" (ngSubmit)="onSubmit(searchForm.value)"> <div class="col-md-2" *ngFor="let filter of this.filters; index as i"> <div class="for ...

Creating stylish rounded corner bars using angular-google-charts

Currently, I'm utilizing angular-google-charts in one of my projects and I have a specific need to create a column chart with rounded corners. https://i.stack.imgur.com/rvJ2H.png Is there a method to achieve this using angular-google-charts? .ts fi ...

Endure the class attribute in Angular 5

My SearchComponent has a route (/search) and SearchDetailComponent has a route (/search-detail:id). In the SearchComponent, there is a searchbox (input field) where I can type any text to start a search. After loading the search results and navigating to ...

Using Angular 2 to efficiently recycle a subcomponent with the same form across multiple parent components while maintaining its state

I've been struggling to find someone with the same issue as me, even though the title may seem familiar. Perhaps I need help rephrasing my question? Here's an explanation: Use case: I have multiple routes (only 2 in the example below) set up fo ...

Convert TypeScript model to JSON while excluding properties with null values

When working with an Angular 4 App and a typescript model, I have defined a Person class as follows: export class Person{ fname:string, lname?:string } The 'lname' property in the model is optional. To populate the model in a component, I u ...

Encountering the error "fn.dataTable.moment is not a function" when trying to use momentjs with DataTables in Angular

Feeling a bit frustrated as I struggle with what seems like a simple issue to fix. Using a DataTable that is working fine, but now I want to make a column of dates sortable in the German date format dd.MM.yyyy. Found the documentation on the official dat ...

The necessity for one type argument is apparent in a generic type, particularly when it is divided into a distinct type

I have a simple scenario that resembles the following and is functioning perfectly: export interface CustomState { someBool: boolean; status: string; } function checkStateDifference<K extends keyof CustomState>(props: { stateKey: K, value: Custo ...