"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

Injecting configurable middleware dependencies in Nest.js allows for dynamic customization of middleware

While many tutorials demonstrate how to inject providers into dynamic modules, most of them only focus on services and not middleware. The challenge arises when attempting to create reusable middleware that also requires injected providers. For instance, ...

Getting to grips with the intricacies of the Gradle "task" syntax

I'm having trouble grasping the syntax of Gradle tasks. After following a tutorial, I created a build.gradle file for building Angular4/SpringBoots projects with Gradle. The build.gradle file includes several task blocks: // added our development b ...

What is the purpose of importing the HttpClientModule in app.module.ts when it has already been imported in a different module specifically for its use?

Currently, I am working with 2 modules named AppModule and BookModule. In BookModule, a component is injected with a service that utilizes HttpClient, so I had to import HttpClientModule in it. However, the application still requires importing HttpClientMo ...

Generate detailed documentation for the functional tests conducted by Intern 4 with automated tools

I need to automatically generate documentation for my Intern 4 functional tests. I attempted using typedoc, which worked well when parsing my object page functions. However, it failed when working with functional test suites like the one below: /** * Thi ...

What are the best ways to personalize my code using Angular Devextreme?

Our development team is currently utilizing Angular for the front-end framework and ASP.net for the back-end framework. They are also incorporating Devextreme and Devexpress as libraries, or similar tools. However, there seems to be difficulty in implement ...

What is the best way to store types in a TypeScript-based React/Next application?

I'm currently in the process of setting up a Next.js page in the following manner const Index: NextPage<PageProps> = (props) => { // additional code... Prior to this, I had defined my PageProps as follows: type PageProps = { pictures: pi ...

Capture data from a Telegram bot and store it in a Google Sheet

I am trying to use a spreadsheet through a Telegram bot as a TODO list so that when I input something on my phone, it is saved in the spreadsheet. (I'm following this tutorial https://www.youtube.com/watch?v=XoTpdxbkGGk, which seems accurate with Goog ...

Develop an Angular module that integrates ngrx store functionality

One thing I'm curious about is how to create an Angular module that utilizes ngrx, has its own store, and can be packaged into an npm package for use in another Angular application. For instance, let's say there's an app1 with its own ngrx s ...

Why is the Last Page display on pagination showing as 3 instead of 2 per items?

When working on Angular 13, I encountered an issue with applying pagination numbers like 1, 2, 3, etc. The problem I faced was that the last page Number should be 2, but it is displaying as 3. Why is this happening? To investigate the issue, I tested my ...

Automatically divide the interface into essential components and additional features

Consider the following interfaces: interface ButtonProps { text: string; } interface DescriptiveButtonProps extends ButtonProps { visible: boolean, description: string; } Now, let's say we want to render a DescriptiveButton that utilize ...

Service in Angular 2 failing to push updates to component

I am currently working on a project where I need to retrieve data from MongoDB using a Service call. So far, the Service call is functioning correctly and logging the data in the console as expected. The challenge arises when dealing with a large response ...

Utilizing the moment function within an Angular application

I've successfully added the library moment.js by running: npm i moment I've included it in scripts and attempted to import it in module.ts. However, when I try to use moment in component.ts, I'm getting an error that says: 'canno ...

Quickly send off an Angular 4 HTTP POST request and move on

I've been experimenting with making a fire and forget request, but none of my attempts seem to be working as expected. The situation is that after completing one subscribable request, I need to redirect to another page. However, before the redirectio ...

Is there a way to configure Angular CLI to enable loading a favicon with a content hash for its filename?

I am looking to cache my website's favicon in the same way I cache css, js, and png files by setting an expires header far into the future. However, I am struggling to figure out how to achieve this. Most resources I come across suggest using a link i ...

Exploring nested static properties within TypeScript class structures

Check out this piece of code: class Hey { static a: string static b: string static c: string static setABC(a: string, b: string, c: string) { this.a = a this.b = b this.c = c return this } } class A { static prop1: Hey static ...

How do you implement an asynchronous validator for template-driven forms in Angular 2?

I have created a custom directive for my asynchronous validator: @Directive({ selector: '[validatorUsername]', providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: ValidatorUsernameDirective, multi: true }] }) export class ValidatorUsern ...

"Sending the selected pass selector as a parameter to the dispatched action is causing a typing

When a selector changes its value, I want to trigger an action. To achieve this, I passed the selector with a subscription instead of passing an observable. selectedSchedulingsOnPopup$ = this.store.pipe(select(selectSchedulingsByBranch)); this.store.disp ...

Two components are loaded simultaneously by Angular

I encountered a strange bug in my Angular2 frontend application. After logging in, I see two components appearing simultaneously - the login component and the main component. In the screenshot above, the login functionality inputs should not be visible. ...

What is the best way to configure the default entry point for a package.json file in a React

I'm having trouble with the default export in my package.json file. when I try to import: import { Component } from 'packagename/'; // size 22kb or import { Component } from 'packagename/dist' // size 22kb; but import { Component ...

Tips for altering the hue of an inline svg within Angular?

I'm not very familiar with SVGs. Currently, I am using ng-inline-svg package to display inline SVG images. Is there a way to change the color of the SVG image? I've looked on stack overflow for solutions but haven't found anything that wor ...