A child support route isn't being displayed

I struggle to grasp the precise algorithm utilized by the angular router, especially when it comes to auxiliary routes.

My Attempts

Despite scouring through documentation, I couldn't find clear insights into how route matching works, particularly for auxiliary routes. However, I stumbled upon a helpful explanation regarding regular routes on Stack Overflow.

Through extensive Google searches, I managed to solve some related issues. One such problem involved a parent with a blank path, hindering the proper functionality of certain auxiliary routes - refer to this post and that post for more details.

An Illustrative Example

This example has been extracted from my project. Let's assume there are two main modules in my application (each equipped with its own routing module, totaling 4).

app.module.ts

...

@NgModule({
  declarations: [
    AppComponent,
    NotFoundComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    AdminModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Answer №1

After conducting further research (this time on Reddit), I was able to find the information I needed. Here is the article that helped me (you can skip everything before

Making the Side Menu adjust to the current Url
but read after). Please note that the answers provided may not be entirely accurate, as they were obtained through experimentation.

How does a child module add its routing configurations to the root configurations? Does lazy loading have any impact on this process? Is it simply appended to the object like so?:

[
    // children module routes
    {
        path: 'dashboard', component: DashboardComponent, children: [
            { path: 'competitions', component: CompetitionsListComponent},
            { path: '', component: DashboardNavComponent, outlet: 'sidebar'},
            { path: 'create', component: CreateComponent, outlet: 'details'},
        ]
    },
    { path: '', pathMatch: 'full', redirectTo: 'dashboard'}

    ...other children module routes...


    // root module routes
    {path: '**', component: NotFoundComponent},
];

Yes, it functions as described where children routes are added at the beginning of the root config array. Lazy loading does not affect this process; it simply loads a module in the specified route. How did I verify this? I included Router as a dependency in one of my components and upon a button click, I logged the config variable of the Router instance.

Why doesn't NotFoundComponent work in certain cases (when errors occur)? Shouldn't it cover every path, or do auxiliary routes need to follow a specific pattern for each outlet like this:

    {path: '**', component: NotFoundComponent, outlet: 'sidebar'}
    {path: '**', component: NotFoundComponent, outlet: 'details'}

Regarding this issue, in my scenario with the URL path

localhost:4200/dashboard/competitions(details:create)
, this method works and prevents the error from being thrown when you specify the pattern on the same level as the auxiliary component rather than in the root. However, if I change the segment to the correct one with an incorrect auxiliary path (referencing the last point) such as
localhost:4200/dashboard/(competitions//wrong:aux-path)
, then one primary pattern in the root handles this situation. Any clarification on this matter would be highly appreciated.

How does an auxiliary route determine which named outlet to use? Does it search for the first parent with the appropriate outlet and if not found, throw an error (excluding the case from the previous point)?

Based on my understanding, No, it functions similarly to regular (primary) routes by using the parent above to identify suitable outlets. If it cannot find a suitable outlet in the direct parent, the content is not rendered. More detailed explanations can be found in the following point.

Lastly, why isn't localhost:4200/dashboard/competitions(details:create) resolving to DashboardComponent with CreateComponent inside? Do I need to specify the URL for auxiliary routes differently? Specifically, how are auxiliary paths resolved when they are children of other non-auxiliary route components?

From the previously referenced article, the explanation I gathered is as follows:

What does a multiple outlet URL look like? By triggering the programmatic navigation call above, the browser will display the following URL: /courses/(development//sidemenu:development)

This URL signifies:

  • the courses URL segment is active
  • inside it, the primary route is set to /courses/development
  • the auxiliary child route 'development' is active for the outlet sidemenu

Therefore, in my case, I should utilize localhost:4200/dashboard(competitions//details:create) where:

  • /dashboard - active segment
  • (competitions//details:create) - multiple outlets for the segment separated by //
  • competitions - primary outlet route
  • details:create - auxiliary outlet route

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

Tips for loading nested JSON data into an Angular Material dropdown list

My task involves extracting data from a JSON object and displaying the difficultyLevel. Despite several attempts, I have been unable to achieve the desired outcome. What changes should be made to the HTML file? const ELEMENT_DATA: data = { questions ...

How to automatically choose a tab in an Ionic 4 modal

I have a button that, when clicked, launches a modal. async launchCalculator() { const calculator = await this.modalController.create({ component: CalculatorPage, componentProps: { dosingType: this.dosingType }, showBackdrop: true, ...

Angular is unable to create a new project

I attempted to create a new project using AngularCLI in the following way: ng new my-app-ambition However, this resulted in the following errors: npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning UNABLE_TO_VER ...

ngFor returning undefined despite array containing value

While iterating through an array using ngFor, I'm encountering an issue where trying to access data in the 'value' variable results in it being undefined. Why is this happening? myArray = ['a', 'b', 'c', 'd ...

Using Mongoose $addToSet to add items to an array only if they are unique

Currently, my code is set up to add new flagDtos using $addToSet without consideration for the uniqueness of item.name. However, I want to change this behavior so that: If item.name is unique, add the new flagDtos object. Otherwise, update the existing fl ...

Rows in angular ag grid are vanishing when data is filtered

My ag grid includes custom components for each column, but I'm facing an issue where the components disappear when filtering the data. For example: the component inside the row To apply filtering, I use an input with a filtering function: <data-gr ...

I am interested in creating a rectangular shape on an image using Angular 2

I am working on a project where I need to draw a rectangle on an image fetched from a URL. While attempting to use canvas for this purpose, I'm facing some difficulties in implementing it correctly. Despite trying out the code below, the canvas remain ...

Adjust the dimensions of an Angular Material 2 dialog by updating the width or height

Is there a way to adjust the dimensions of an open Angular Material 2 dialog, either its width or height? I attempted to modify the size of the dialog by obtaining a reference to it and using the updateSize method within the dialog. Unfortunately, I belie ...

`A constant stream of observations being triggered`

In my application, there is a specific page that retrieves and displays the members. The API response includes pagination information, and only 5 users are shown on the page at a time. Below is the method within the member.service that handles member retri ...

What is the best way to display two arrays next to each other in an Angular template?

bolded text I am struggling to display two arrays side by side in an angular template. I attempted to use ngFor inside a div and span but the result was not as expected. A=[1,2,3,4] B=[A,B,C,D] Current Outcome using ngFor with div and span : Using Div : ...

Learn how to break down Angular 2 with Typescript in just 5 minutes by troubleshooting issues

I've been delving into the world of TypeScript and Angular 2 by following the guide at https://angular.io/guide/quickstart. After going through all the steps, I encountered some errors with the final step npm start. Here's what I got: Microsoft ...

Typescript is unable to interpret an anticipated overloaded function signature

I'm currently facing challenges with TypeScript overload resolution. When using the googleapis library with TypeScript to fetch all tag manager accounts records, the list function requires pagination if the response body contains a nextPageToken. I a ...

The angular web app is having trouble displaying the Font Awesome icon

My package.json file includes the following dependencies: "@fortawesome/angular-fontawesome": "^0.4.0", "@fortawesome/fontawesome-free": "^5.13.1", "@fortawesome/fontawesome-svg-core": "^1.2. ...

Retrieve the complete list of exported elements within the document

My collection of minor components is extensive: export const A = () => {...} export const B = () => {...} ... export default [A, B, ...]; Each time I add a new component to the file, there's a chance I might overlook adding it to the expor ...

"Angular 2: Organize and refine data with sorting and

Sorting and filtering data in Angularjs 1 can be done using the following syntax: <ul ng-repeat="friend in friends | filter:query | orderBy: 'name' "> <li>{{friend.name}}</li> </ul> I have not been able to find any ex ...

Error encountered: EPERM

I am currently using node v6.11.2, npm v5.3.0 and angular/cli v1.2.7. Recently, I've started encountering a new error message during most of my npm installs that I have never seen before... mmeppiel@MC-LT-MMEPPIEL MINGW64 ~/Desktop/Angular Solutions ...

Having trouble resolving the signature of a class decorator when invoked as an expression with @Injectable in Angular

Error Message: Unable to resolve the signature of a class decorator when called as an expression. The argument type 'ClassDecoratorContext' is not compatible with the parameter type 'string | symbol | undefined'. After creating a book ...

Different methods for organizing an array of strings based on eslint/prettier

I possess an assortment of keys that I desire to sort in alphabetical order whenever I execute eslint --fix/prettier. My inference is that such a feature does not exist by default due to its potential impact on the code's behavior. Therefore, my quer ...

A guide to styling rows individually in an ngFor loop with Angular 5

I am currently developing a table that populates rows using the *ngFor directive: <tr *ngFor="let car of cars"> <td>{{car?.id}}</td> <td>{{car?.date | date : "short"}}</td> <div [ngSwitch]="car?.state ...

Troubleshooting routing errors when deploying Angular 6 on hosting name.com

After loading my Angular 6 application using CLI in a standard hosting service at name.com, I encountered some issues. Here are the steps I followed: Ran 'ng build --prod' command This command generated the dist folder In the root directory of ...