"Encountering issues with the functionality of two Angular5 routers

main.component.html

[...]
<a routerLink="/company-list">Open</a>
[...]
<main>
<router-outlet name="content"><router-outlet>
</main>
[...]

app.compoment.html

<router-outlet><router-outlet>

app.routing.module.ts

import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import { Router } from "@angular/router";
import { Routes } from "@angular/router";

const ROUTES:Routes =[

    {path:'principal', loadChildren: 'app/main/main.module#MainModule'}
]

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

main.routing.module.ts

import { Routes } from "@angular/router";
import { MainComponent } from "./main.component";
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import { CompanyListComponent } from "../company/company-list/company-list.component";

const MAIN_ROUTES: Routes = [
    {path: '', component: MainComponent},
    {path: 'company-list', component:CompanyListComponent, outlet: 'content'}
];

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

app.module.ts

@NgModule({
  declarations: [
    AppComponent,


  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,                 
    MainModule,
    AppRoutingModule,   

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

main.module.ts

@NgModule({
declarations:[
    MainComponent
],
 imports:[
    MaterializeModule,
    MainRoutingModule,
    CompanyModule

 ],
 exports:[MainComponent]
})
export class MainModule{}

Now let's discuss the issue I'm facing. When clicking on the company-list route, an error appears in the console:

Uncaught (in promise): Error: Can not match any routes. URL Segment: 'company-list' Error: Can not match any routes. URL Segment: 'company-list'

I have tried several solutions to resolve this but without success so far. My goal is to render the ComponentListComponent inside the main tag of my MainComponent. Any assistance would be appreciated.

Answer №1

It seems like there might be a solution to your issue. Have you considered creating EmpresaListasComponent as a child route of PrincipalComponent? That could potentially solve the problem.

const PRINCIPAL_ROUTES: Routes = [
    {path: '', component: PrincipalComponent,
      children: [
        {path: 'empresa-list', component:EmpresaListasComponent, outlet:'content'}
    ]
},
];

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 functionality to automatically close the Material Sidebar upon clicking a navigation item is not functioning properly

After navigating by clicking on Sidebar nav items, I am trying to auto close the Material Sidebar. However, it doesn't seem to work in that way for me. I have created a Stackblitz to demonstrate my issue: Access the Stackblitz Editor Site here: http ...

Angular 4 animations failing to run on Safari iOS 9.3

In my current app testing phase, I noticed that the angular animations are not functioning as expected in Safari iOS 9.3. Despite spending hours trying to troubleshoot the issue, I still couldn't resolve it on my own. Therefore, I am seeking assistanc ...

How can I adjust the appearance of an HTML tag within an Angular component?

I have created an Angular component with the following definition: import { Component, Input, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'rdc-dynamic-icon-button', templateUrl: './dynamic-icon-button. ...

The rendering process in ag-grid is resulting in the service component initialized from an event to become null

Currently, I am utilizing ag-grid and need help understanding a specific issue. In my method for preparing GridOptions, I have set up an onCellValueChanged event that triggers a service component to access the database and populate the data. However, when ...

Error message: "Issue occurs when sending keys to protractor element's text value and

Having trouble running this code in Protractor as I keep encountering errors, and I'm unable to retrieve the value of the anpr_box_input text. Error message: ManagedPromise::871 {[[PromiseStatus]]: "pending"} failed - should have a valid license ...

Error in Angular: Trying to access the property 'id' of an undefined value

I am facing an issue with a div tag in my HTML file. The code snippet looks like this: <div *ngIf="chat.asReceiver.id != user?.id; else otherParty"> Unfortunately, it always returns the following error: ERROR TypeError: Cannot read propert ...

Encountering "Object is possibly undefined" during NextJS Typescript build process - troubleshooting nextjs build

I recently started working with TypeScript and encountered a problem during nextjs build. While the code runs smoothly in my browser, executing nextjs build results in the error shown below. I attempted various solutions found online but none have worked s ...

What is the best way to perform a single asynchronous or promise-based fetch request and utilize the retrieved data across multiple functions?

Is there a way to optimize fetching data from an API and use the fetched data in multiple methods within the same service without making redundant requests in the Network? export class MediaService { constructor(private mediaAppApiService: MediaAppApiS ...

unable to assign an array to a different array in typescript

I'm facing an issue with assigning values to the private kitems array in my class. Despite defining it as kitems:any[], when I try to assign a value using this.kitems = items; and then log this.kitems, it shows up as an empty array. createprofile() { ...

Tips for deleting multiple objects from an array in angular version 13

I am facing an issue where I am trying to delete multiple objects from an array by selecting the checkbox on a table row. However, I am only able to delete one item at a time. How can I resolve this problem and successfully delete multiple selected objects ...

Tips for resolving the ExtPay TypeError when using Typscript and Webpack Bundle

I am currently trying to install ExtPay, a payment library for Chrome Extension, from the following link: https://github.com/Glench/ExtPay. I followed the instructions up until step 3 which involved adding ExtPay to background.js. However, I encountered an ...

The DefaultTheme in MaterialUI no longer recognizes the 'palette' property after transitioning from v4 to v5, causing it to stop functioning correctly

Currently in the process of transitioning my app from Material UI v4 to v5 and encountering a few challenges. One issue I'm facing is that the 'palette' property is not recognized by DefaultTheme from Material UI when used in makeStyles. Thi ...

What is the process for importing files with nested namespaces in TypeScript?

Currently, I am in the process of transitioning an established Node.js project into a fully TypeScript-based system. In the past, there was a static Sql class which contained sub-objects with MySQL helper functions. For instance, you could access functions ...

Enrich TypeScript objects by incorporating additional properties beyond the ones already present

If I have an expression and want to add extra properties without repeating existing ones, how can I achieve that? For instance, if the expression is a variable, it's simple to include additional fields (like adding field e): const x = { a: 1 }; cons ...

typeorm migration:generate - Oops! Could not access the file

When attempting to create a Type ORM migration file using the typeorm migration:generate InitialSetup -d ormconfig.ts command, I encountered an error: Error: Unable to open file: "C:\_work\template-db\ormconfig.ts". Cannot use impo ...

Clearing dropdown values when navigating back on a page in Angular 6: A step-by-step guide

Image Within the App Component, I have implemented a dropdown list. When an option is selected from the dropdown, it should navigate to another page using routing. Additionally, upon clicking the back button, it should return the user to the app compone ...

React with Typescript - cannot be expressed as a function

I am currently exploring ReactJS and Typescript. While trying to authenticate a user using the methods below, I encountered the following error message: Unhandled Rejection (TypeError): auth.authenticate is not a function onSubmit src/components/Login/ind ...

Displaying a div component in React and Typescript upon clicking an element

I've been working on a to-do list project using React and TypeScript. In order to display my completed tasks, I have added a "done" button to the DOM that triggers a function when clicked. Initially, I attempted to use a useState hook in the function ...

Is it necessary to retrieve the data that was posted from the back-end? Implementation using Angular and Node.js

I need some advice on how to handle worker data in my Angular, NodeJS, and MySQL app. In the FORM, users can add workers whose information is then sent to the backend for processing. The user can preview the posted information and delete workers if needed. ...

What is the best way to attach an attribute to a element created dynamically in Angular2+?

After reviewing resources like this and this, I've run into issues trying to set attributes on dynamically generated elements within a custom component (<c-tabs>). Relevant Elements https://i.stack.imgur.com/9HoC2.png HTML <c-tabs #mainCom ...