Exploring the Depths of Angular 11's Named Nested Router Outlets

I am facing an issue with my router configuration. Here is the current setup:

const appRoutes: Routes = [
  { path: '', component: LoginComponent},
  { path: 'login', component: LoginComponent },
  { path: 'main', component: MainComponent, canActivate: [AuthGuard], children: [
      { path: 'client', component: ClientComponent, outlet: 'c', children: [
          { path: 'clientinfo', component: ClientInfoComponent, outlet: 'i', children: [
              { path: 'cafe', component: ClientCafeComponent},
              { path: 'membership', component: ClientMembershipComponent },
              { path: 'pt', component: ClientPtComponent }
            ] }
        ] },
      { path: 'coach', component: CoachComponent, outlet: 'c'}] },
,
];

I am trying to find a way to load ClientInfoComponent from ClientComponent and ClientMembershipComponent from ClientInfoComponent using [routerLink]. Any suggestions on how to achieve this?

I attempted the following syntax:

[routerLink]="['/main/(c:client)/(i:clientinfo/)']"

but unfortunately, it did not work as expected.

Thank you for your assistance in advance!

Answer №1

After much searching, I have finally found a solution to my question and wanted to share it with others. I made changes to my routes as shown below:

const appRoutes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full'},
  { path: 'login', component: LoginComponent },
  { path: 'main', component: MainComponent, canActivate: [AuthGuard], children: [
      { path: 'client', component: ClientComponent, canActivate: [AuthGuard], outlet: 'c' },
      { path: 'client/clientinfo', component: ClientInfoComponent, outlet: 'c', children: [
          { path: 'cafe', component: ClientCafeComponent},
          { path: 'membership', component: ClientMembershipComponent },
          { path: 'pt', component: ClientPtComponent }
        ] },
      { path: 'coach', component: CoachComponent, outlet: 'c'}] },
];

Also, in the ClientComponent file:

[routerLink]="['/main', { outlets: { c: ['client', 'clientinfo']}}]"

I hope this can be of assistance to someone facing a similar issue.

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

Transforming the api response object into a map containing nested maps with string values

Is there a way to optimize the code below without using loops? Although I prefer not to use loops in my code, the current implementation relies on them. I'm curious if achieving the same result is possible with a different approach. Code: ts private ...

Can a function be annotated in order to inform the TypeScript compiler that it has verified the type of a class property?

How can I annotate `readText` in the code snippet below to assure the compiler that `this.text` is of type `string` and not `string | undefined`? type MyResponse = { text: () => Promise<string>; }; class ResponseVerfier { response: MyRespons ...

What is the proper way to utilize mapped types in TypeScript module declarations?

How can I create a type declaration for an external module and use a mapped type for this declaration? Currently, the module appears as: declare module "deferred-regl"{ import { Regl } from 'regl' type IDregl<T> = { setRe ...

Using useState as a global variable alongside contextAPI in TypeScript: A solution sought

--Environment setup: Windows 10, VScode --Technologies: React, TypeScript I am looking to utilize Context API for global variable management without using useReducer. The variables I need to manage are objects fetched from an axios request. const resu ...

Switch from flexbox layout to begin on the next column within the same row

I am attempting to create a CSS layout where, after a specific element like :nth-child(6), the elements will break and form a separate column within the same row. The parent element should split into 2 columns after every 6th element in the same row, then ...

What could be preventing me from setting a boolean variable within an Observable?

After retrieving data from the Service, I am attempting to hide a specific div element. Below is the HTML code: <progressbar *ngIf="isLoadingBootStockData" [value]="100" type="default"> </progressba ...

Handling type errors with React Typescript MuiAccordion OnChange event handler

I'm a beginner in typescript and seeking advice on defining the type for an event handler. I have a component that utilizes material ui Accordion and triggers the handler from a container. Therefore, I need to specify the type of handleChange in my co ...

How can I override the default ngModel behavior in a custom Angular component?

While debugging my component that utilizes ng-select, I noticed that every time I type into the input field, the ngModel property changes even though I am not explicitly using ngModel in my view. I have removed all instances of ngModel except for the class ...

Encountering a Start-up Issue with Angular2 on Windows 7

Just starting out with Angular and eager to dive deeper into Angular2. I meticulously followed the initiation guide to create the angular2-quickstart project. However, when executing the npm start command, the browser starts up but abruptly fails after jus ...

Why does VSCode open a React app in Edge instead of Chrome?

Recently, I began a new project using the react-create-app template with typescript. However, when I run npm run dev, it unexpectedly opens in the Edge browser instead of Chrome. Does anyone know how to make it open in Chrome instead? ...

Error arises in Typescript due to inability to assign a value after explicit type verification

Here is a function that returns a JSX component: const getListContent = () => { switch (true) { case loading: return <ListLoadingIndicator/>; case error !== undefined: return <ListError error={error} ...

Troubles arise when compiling TypeScript to JavaScript

I have been experimenting with TypeScript, specifically for working with classes. However, I am facing an issue after compiling my TS file into JS. Below is the TypeScript code for my class (PartenaireTSModel.ts): export namespace Partenaires { export ...

Expanding macros in TypeScript

I am working on translating the functionality of this C code into TypeScript. The main goal of this piece of code is to streamline error checking, inspired by JPL's The Power of Ten principles. I have been struggling to implement this in TS. #define ...

The variable 'minSum' is being referenced before having a value set to it

const arrSort: number[] = arr.sort(); let minSum: number = 0; arrSort.forEach((a, b) => { if(b > 0){ minSum += minSum + a; console.log(b) } }) console.log(minSum); Even though 'minSum' is defined at the top, TypeScript still throws ...

best way to transfer boolean variable from one angular service to another

Can anyone help me with passing a boolean value from one service to another service file in Angular? I'm encountering an issue where the boolean value is showing as undefined. I haven't been able to find any examples or documents related to this. ...

The autocomplete feature in Atom is not functioning as expected

Autocomplete+ is included with the installation of Atom and is activated by default. I have noticed that when I am coding, no suggestions are appearing. What could be causing this issue? Do I need to adjust any files in order for Autocomplete+ to functio ...

Trouble updating values in Javascript objects

I'm having trouble understanding a problem I am experiencing. When I receive a Json object as a Websocket message from a hardware device, the property `uiAppMsg` is encoded in base64. After decoding it, I attempt to reassign it to the `uiAppMsg` prop ...

Keeping an object in a multidimensional array based on its ID in Angular 4/Ionic 3 without removing it

Exploring a complex data structure: [{ propertyoutsideid: 1, items: [ {itemId: 1, something: 'something'}. {itemId: 2, something: 'something'}. {itemId: 3, something: 'something'}. ] },{ prope ...

Angular API snapshot error: The type 'IJobs' does not match the expected type 'IJobs[]'

Currently, I am in the process of learning and attempting to construct a job board using Angular 10. Although my API setup seems to be functioning properly, when navigating to the job detail page on Chrome, an error is displayed: ERROR in src/app/job-det ...

The Angular application has been successfully compiled, yet it is not loading in the browser. Additionally, an Uncaught ReferenceError is being thrown, stating that 'process

After updating my Angular application from version 11 to version 12, I spent a lot of time fixing errors and finally got the application to compile successfully. However, when I try to view it on the local server, nothing is appearing on the screen. There& ...