Angular 17 - Exploring the Additional Route Options

I am encountering some challenges while setting up the auxiliary route in Angular 17, likely stemming from the transition to standalone components. Below is my current configuration:

export const FEATURE_ROUTES: Routes = [
  {
    path: '',
    component: ContactComponent,
    children: [
      {
        path: '',
        pathMatch: 'full',
        redirectTo: 'contact',
      },
      {
        path: 'education',
        component: EducationComponent,
        // loadComponent: () =>
        //   import('./modules/education/education.component').then(
        //     (c) => c.EducationComponent
        //   ),
        outlet: 'modal',
      },
    ],
  },
];
export const routes: Routes = [
  { 
    path: 'contact', 
    loadChildren: () => import('./feature.routes')
      .then((r) => r.FEATURE_ROUTES), 
  },
  { 
    path: 'skills', 
    outlet: 'modal', 
    loadComponent: () => import('./modules/skills/skills.component')
      .then((s) => s.SkillsComponent),
  },
];

The routing configuration is imported in main.ts following the new Angular guidelines.

app.component.html

<button (click)="navigateToContact()">Open contact</button>
<router-outlet></router-outlet>
<div class="modal-outlet">
  <router-outlet name="modal"></router-outlet>

Navigating to the contact page functions as expected.

public navigateToContact(): void {
  this.router.navigate(['contact']);
}

contact.component.html

<button (click)="loadEducation()">Load educations</button>

<router-outlet></router-outlet>
<router-outlet name="test"></router-outlet>

Below is the loadEducation method:

public loadEducation(): void {
  this.router.navigate([
    '/',
    { outlets: { modal: ['contact', 'education'] } },
  ]);
  // this.router.navigate(['contact/education']);
}

I aim to achieve a functional URL structure:

http://localhost:4200/contact(modal:education)

But I am running into the error below:

Error: NG04002: Cannot match any routes. URL Segment: 'contact/education'

Answer №1

To access the auxiliary route for EducationComponent, use the following navigation method:

public loadEducation(): void {
  this.router.navigate(['contact', { outlets: { modal: ['education'] } }]);
}

As a result, the URL will look like this:

/contact(modal:education)

See Demo on StackBlitz

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

Retrieving a FirebaseObjectObservable child in Angularfire2 is straightforward

Can you target a specific child of a FirebaseObjectObservable in Angular? Take a look at RcTestAppComponent.save() function below for commented lines. Here is an example: https://github.com/angular/angularfire2/blob/master/docs/3-retrieving-data-as-lists. ...

Storing multiple fields using LocalStorage in Angular2

After finding inspiration from the example at https://github.com/PillowPillow/ng2-webstorage, I successfully managed to store and retrieve the boundValue. Now, I encounter a new challenge with a list of bots: bot.component.html <tr *ngFor="let bot of ...

Updating data in Angular 5 without using ngFor: A step-by-step guide

I have a collection stored in Firestore, and I am looking to update the proyecto.descripcion field within the collection when the "Update" button is pressed. However, I am struggling to understand how to achieve this without using the *ngFor method. You c ...

Exploring Angular's HTTPClient with Test API

Recently, I developed a simple method to fetch the JSON response object from a URL API endpoint. My goal is to extract this output and place it into an element within an HTML template... Below is the function that I created for the API endpoint which ret ...

Having trouble accessing a variable from the material theme in Angular 7

Currently, I am working with Angular 7.0.3 and endeavoring to establish an scss variable with the primary color of my material theme. // src/styles/_variables.scss @import "~@angular/material/theming"; @include mat-core(); $app-primary: mat-palette($mat-i ...

The ng-content within the ng-template is visible exclusively within a single ng-container

I am currently developing a flip panel consisting of three parts: panel-tool-bar panel-front panel-back The tool-bar contains a fixed element, the flip button. Within my flip-panel.component, I have an ng-template for the tool-bar to ensure it is displ ...

Can Angular and Firestore work together to create a route guard for the login screen that verifies the user attempting to access the route?

In my Angular application, I have implemented a route guard. If a user happens to visit domain.com/login while already logged in, I want to redirect them to a different route. There is a specific type of user account in Firestore with the attribute &apos ...

Guide to capturing scroll event in Angular 6

Is there a way to prevent the scroll event from firing? I attempted using event.preventDefault() within the HostListener, but it doesn't seem to be effective. Similarly, event.stopPropagation() and event.stopImmediatePropagation() aren't having ...

Assignment of Angular Component Class Variable in One Function Results in Undefined Value in Another

I am currently facing an issue with a component that has a ViewChild() binding to a child component, which is used to execute a function in the child component. This function takes a true or false argument and is intended to assign the value to a class var ...

Is there a way to locate all items that satisfy a specific criterion within JSON Data?

Utilizing data from an API-Call, I have established a many-to-many relationship - illustrated with the examples of people and movies. Multiple individuals can watch one movie, and one person can view several movies. In the Angular Frontend, when a person ...

In the latest version of Expo SDK 37, the update to [email protected] has caused a malfunction in the onShouldStartLoadWithRequest feature when handling unknown deeplinks

After updating to Expo SDK 37, my original code that was previously functioning started encountering issues with <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e7c6b6f6d7a23606f7a67786b23796b6c78667f79627a">[email prot ...

Comparing the Calculation of CSS Selector Specificity: Class versus Elements [archived]

Closed. This question requires additional information for debugging purposes. It is not currently accepting answers. ...

Typedoc Error: Attempted to assign a value to an undefined option (mode)

After installing typedoc with the command npm install typedoc --save-dev, I proceeded to add typedocOptions to tsconfig.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", // ...some lin ...

Exploring the Functionality of Custom Properties in react-table with TypeScript

Currently, I am constructing a table using react-table. However, TypeScript is throwing errors regarding the properties I have included in the columns. This is how my columns are structured: const columns = useMemo( () => [ { Header: & ...

Encountering an error when attempting to execute the command "npm install"

Here is the error message I am receiving: npm ERR! code E401 npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47, Basic realm="https://pkgsprodcus1.pkgs.visualstudio.com/" ...

Verify the length of an array within an object using JavaScript

I am facing a problem with an object. Here is what it looks like: const array = { "entities": [ { "annexes": [ { "buildingUniqueIds": [] }, { ...

Is it necessary to transmit rule specifics to Stepfunctions?

Is it feasible to achieve what I'm attempting, or am I starting with an impossible task? When a Event Bridge Rule is triggered by an added event pattern, like shown below, should the detailed information be included in the step input? const rule = ne ...

Error message indicating that the Mikro ORM migration command could not locate the configuration file

I have been following Ben Awad's comprehensive full stack tutorial: youtube tutorial link. At around the 30-minute mark, things become relevant. Encountering an issue with the command npx mikro-orm migration:create. Error: MikroORM config file not fo ...

Error: When using the axios package in TypeScript code within a Firebase cloud function, there is an issue with reading the property 'post' which is undefined

I am attempting to implement the following logic in a Google Cloud Function. When I run this function using the emulator, I consistently encounter the error message ⚠ functions: TypeError: Cannot read property 'post' of undefined I have tried ...

What's up with @use behaving oddly in Angular + SASS imports from node_modules?

Encountering an issue when importing styles using @use in my Angular project. In the styles.scss file, @use "@angular/material" as mat; works perfectly. However, @use "ngx-popperjs" as ngx-popperjs; results in an error stating "Can& ...