The child component is not displayed when utilizing Angular routing

Whenever I try to access the URL "funzioniUtenteBase/ricercaModulo," the path is reached but the RicercaModuloComponent is not visible. I have observed that adding "router-outlet" inside home-utente-base-component.html makes the RicercaModuloComponent appear. However, this results in both HomeUtenteBaseComponent and RicercaModuloComponent being displayed simultaneously. What I actually want is for HomeUtenteBaseComponent to disappear and only RicercaModuloComponent to be visible.

How can I resolve this issue? Thank you!

app-routing.module.ts:

    const routes: Routes = [
  {
    path: "funzioniUtenteBase",
    loadChildren: () => import('./features/components/home-utente-base/home-utente-base.module').then(m => m.HomeUtenteBaseModule)
  },
  {
    path: "funzioniTecnicoDelegato",
    loadChildren: () => import('./features/components/home-tecnico-delegato/home-tecnico-delegato.module').then(m => m.HomeTecnicoDelegatoModule)
  },
  {
    path: "funzioniSupervisore",
    loadChildren: () => import('./features/components/home-supervisore/home-supervisore.module').then(m => m.HomeSupervisoreModule)
  }
];

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

app.component.html:

<div
  class="layout-wrapper"
  [ngClass]="{'layout-menu-horizontal': 'horizontal'}">
  <div class="layout-main">
    <app-toolbar></app-toolbar>
    <app-breadcrumb></app-breadcrumb>
    <div class="layout-content">
      <router-outlet></router-outlet>
    </div>
    <app-footer></app-footer>
  </div>
</div>

home-utente-base-routing.module.ts:

const routes: Routes = [
  {
    path: '',
    component: HomeUtenteBaseComponent,
    children: [
      {
        path: 'ricercaModulo',
        component: RicercaModuloComponent
      }
    ]
  }
];

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

home-utente-base.component.ts:

<div class="ui-grid-fixed">
  <div class="formgrid grid">
    <div class="field col-12 md:col-3">
      <a
        class="square-box"
        routerLink="./ricercaModulo">
        <img src="./../../../../assets/layout/images/icon-cerca.svg">
        <p>Ricerca modulo</p>
      </a>
    </div>
  </div>
</div>

Answer №1

To resolve the issue, simply define both routes as siblings rather than using a parent-child relationship.

const routes: Routes = [
  {
    path: '',
    component: HomeUtenteBaseComponent,
    pathMatch:'full',
  },
  {
    path: 'ricercaModulo',
    component: RicercaModuloComponent
  }
];

Cheers!

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

Is there a way for me to obtain the full error message after a failed fetch request?

I'm trying to capture all errors from the fetch function, including the specific red highlighted details as a string: https://i.sstatic.net/GtHxv.png But when I catch an error in my code, all I get is "Failed to fetch." Here's what my code looks ...

Saving customer pictures in the cloud with AWS

For my current project, I am developing an app using ionic2 that interacts with an API created using Flask. As part of the profile setup process, users are given the option to upload their own images. I have decided to store these images in an S3 bucket an ...

The functionality of Angular 2 md-radio buttons in reactive forms seems to be hindering the display of md-inputs

Currently, I am following the instructions for implementing reactive form radio buttons on a project using Angular 2.1.2 and Google's MD-alpha.10 Atom-typescript shows no errors in my code. However, when testing the application, I encountered the foll ...

Error with preflight request in Angular .NET Core API CORS configuration

Having trouble setting up CORS with Angular and .NET Core 2.1? Here's the error message I'm encountering: Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: Response to preflight request doesn&apos ...

Null errors are encountered when working with Angular 4 Reactive Forms FormControl

When navigating through the text inputs without providing any input, the error message divs are displayed to indicate that the required validator is functioning correctly. However, if I enter anything into one of the fields, an error is immediately thrown ...

Utilizing TypeScript to Populate an observableArray in KnockoutJS

Is there a way to populate an observableArray in KnockoutJS using TypeScript? My ViewModel is defined as a class. In the absence of TypeScript, I would typically load the data using $.getJSON(); and then map it accordingly. function ViewModel() { var ...

Retrieving output from a Typescript React Component

Is there a way to retrieve the result from the component class using this method? When I call the ExampleSelectionComponent, it displays the desired output but I also need to access the value of exampleSelectionId in this class. public render() { const ...

Is it achievable to display keys from an interface using Typescript in node.js?

Using node.js with typescript, I have a query. I defined a type from interfaces key, and I'm wondering if it's feasible to display the key list? interface IFooReal { prop1: string; prop2: number; } type KnownKeys<T> = { [K in ...

Install a MEAN Stack application on the server of my choosing

My MEAN Stack app is running smoothly in development mode. I am now looking to deploy it on my company's server, but I am struggling to find resources on deploying MEAN apps on a server of my choice. Most of the tutorials I found focus on platforms li ...

Show a checkmark or X depending on the condition in Javascript

I have an array of data that I want to compare to the input in a text field. If the input matches an element in the array, I want to display a checkmark, and if it doesn't match, I want to display a crossmark. However, I'm having an issue where ...

Access an external URL by logging in, then return back to the Angular application

I am facing a dilemma with an external URL that I need to access, created by another client. My task is to make a call to this external URL and then return to the home page seamlessly. Here's what I have tried: <button class="altro" titl ...

Issue with setting cookies in Node.js using Express

Recently I made the switch from regular JavaScript to TypeScript for my project. Everything seems to be functioning properly, except for session handling. This is the current setup of my project: Server.ts App.ts /db/mongo/MongoHandler.ts and some other ...

Experience the power of combining React with typescript, webpack, and ui-router-react for

After carefully studying the ui-router-react documentation (), I am encountering several challenges with webpack compilation when importing import {UIRouter, UIView, UISref, UISrefActive, pushStateLocationPlugin} from 'ui-router-react'; This is ...

`Drizzle ORM and its versatile approach to SELECT statements`

Looking to improve the handling of options in a function that queries a database using Drizzle ORM. Currently, the function accepts options like enabled and limit, with potential for more options in the future. Here's the current implementation: type ...

Sending data from a parent component to a child component via reference

I am facing an issue with my 2 components: parentComponent and childComponent. The parentComponent contains a FormGroup named parentForm, which is passed to the childComponent through @input: export class parentComponent { ... parentForm: FormGroup; .. ...

Filtering an array in Angular based on two specific property values

I am facing a challenge with deleting items from an array based on two property values. If we were to compare it to the classic Sql delete command, the equivalent would look something like this: DELETE oImages WHERE idOffertRow = 1 and idProductImage = 2 ...

The body content of the webpage needs to be updated without altering the header and footer, all while avoiding a page

On my website, I have a header menu that includes buttons for "home" and "about us." The default page is set to the home page. Within the home page, there is a specific link. When this link on the home page or the "about us" button is clicked, I want the ...

Refresh the information in the <ion-datetime> component by utilizing the formGroup

I am currently working with a form that has been created using 'FormBuilder'. The form includes a date control and I am trying to figure out how to update the data in that control using the patchValue() method. In the template, the control has d ...

The attribute 'loaded' is not found in the 'HttpSentEvent' data type

Currently, I have implemented an Angular HTTP post request with the following parameters: this.http .post<{ body: any }>(environment.api.file.upload, reqBody, { reportProgress: true, observe: 'events', }) .subscribe((ev: HttpE ...

When using tsdx with React, null values can prevent proper usage of hooks

Recently, I attempted to develop a React TypeScript component using tsdx for compilation and encountered a roadblock while debugging. The package appears to be successfully published and installed without any errors. However, when trying to use it, I consi ...