Does the routing in Angular 2 get disrupted by parameter breaks in sub-modules?

In my Angular 2 application, I am encountering an issue with routing to my line module. Currently, I have two submodules - login and line. The routing to the login submodule is working well. However, when I attempt to route to the line module with route params such as /line/param1/param2, it breaks the navigation flow.

Here is an overview of my root module:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    LoginModule,
    LineModule,
    routing
  ],
  providers: [appRoutingProviders],
  bootstrap: [AppComponent]
})
export class AppModule { }

This is how my app.routes.ts file looks like:

import { Routes, RouterModule } from '@angular/router';

const appRoutes: Routes = [
  { path: 'login', loadChildren: 'login/login.module', pathMatch: 'prefix'},
  { path: 'line', loadChildren:'line/line.module', pathMatch: 'prefix'}
];

export const appRoutingProviders: any[] = [];
export const routing = RouterModule.forRoot(appRoutes);

The LoginModule functions correctly with its child routes. However, issues arise when trying to navigate to the LineModule.

Here is my line.module.ts:

import { CommonModule } from '@angular/common';
import { MaterialModule } from '@angular/material';
import { LineComponent } from './line.component';
import { lineRouting } from './line.routes';
import { DataService } from './services/data/data.service';
@NgModule({
  imports: [
    CommonModule,
    MaterialModule,
    lineRouting
  ],
  providers:[DataService],
  declarations: [LineComponent]
})
export class LineModule { }

And the line.routes.ts file:

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { LineComponent } from './line.component';

const lineRoutes: Routes = [{
    path: 'line',
    component: LineComponent,
    children: [
        { path: '/:dep/:id', component: LineComponent }
    ]
}];

export const lineRouting: ModuleWithProviders = RouterModule.forChild(lineRoutes);

When routing to http://localhost:4200/line, everything works fine although there is a service error due to undefined dep and id values. However, navigating to

http://localhost:4200/line/finance/line3
leads to this error:

EXCEPTION: Uncaught (in promise): Error: Cannot find module 'line/line.module'.

Error: Cannot find module 'line/line.module'

I have tried altering the path in app.routes.ts to line/:dep/:id, but the outcome remains the same. What could be causing this issue?

Answer №1

To resolve a comparable problem, I successfully tackled it by eliminating the initial slash in the path. Here's what you can do:

children: [
    { path: ':dep/:id', component: LineComponent }
]

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

Utilizing google.maps.places.Autocomplete within a JHipster application with a modal pop-up feature

I am struggling to make google.maps.places.Autocomplete function properly within a modal in Jhipster 4.6.1 / angular 4.2. The issue lies with the display of results, as the z-index of the .modal seems to be conflicting with the google css, resulting in no ...

What is the most efficient way to retrieve 10,000 pieces of data in a single client-side request without experiencing any lag

Whenever I retrieve more than 10 thousand rows of raw data from the Database in a single GET request, the response takes a significant amount of time to reach the client side. Is there a method to send this data in smaller chunks to the client side? When ...

Is it possible for Go's http server to compile TypeScript?

My current setup involves a NodeJS Application that launches an http server and utilizes client side code written in TypeScript with Angular 2. I'm curious if it's possible to achieve the same functionality using Go programming language? I trie ...

Issue: An object with keys {} is not suitable as a React child, causing an error

I am new to TypeScript and seeking help from the community. Currently, I am working on a to-do list project where I am using React and TypeScript together for the first time. However, I encountered an error that I cannot decipher. Any assistance would be g ...

I am having trouble with updating an array in React useState. Every time I try to make changes, it keeps reverting back to the initial state. What could

My current task involves managing a state array called monthlyIncidents, which contains 12 numbers that need to be updated under certain conditions. I attempted to update the elements by copying the array, modifying the specific element, and then updating ...

Develop a user interface that includes the ability to have unspecified properties of an unspecified data type,

interface Sample { value?: string [prop: string]: any } const sampleObject: Sample = { title: 'John' } const data = sampleObject.title By including "any" in the interface, it eliminates the automatically assumed "string" type for the p ...

Is there a way to modify the button exclusively within the div where it was pressed?

I plan to incorporate three buttons in my project (Download, Edit, and Upload). Upon clicking the Download button, a function is triggered, changing the button to Edit. Clicking the Edit button will then change it to Upload, and finally, clicking the Uplo ...

Using Angular to create a dynamic form with looping inputs that reactively responds to user

I need to implement reactive form validation for a form that has dynamic inputs created through looping data: This is what my form builder setup would be like : constructor(private formBuilder: FormBuilder) { this.userForm = this.formBuilder.group({ ...

Having trouble resolving the typescript package while integrating with another module

Attempting to develop a basic npm package with TypeScript and bundle it using webpack. When trying to use the package in another module, such as a react application named 'module A.' Within module A, the 'myLibrary' package is installe ...

The name "Identifier" has already been declared before

I am currently working on a social network project to enhance my skills in nodejs and reactjs. While debugging the backend code for /signin using Postman, I encountered an error that prevents me from launching the node server. The error message displayed i ...

How to transfer a parameter in Angular 2

I am currently facing a challenge in passing a value from the HTML file to my component and then incorporating it into my JSON feed URL. While I have successfully transferred the value to the component and displayed it in the HTML file, I am struggling to ...

The setInterval function is active in various components within Angular 6

Recently, I started using Angular(6) and incorporated the setInterval function within a component. It's functioning properly; however, even after navigating to another route, the setInterval continues to run. Can someone help me determine why this is ...

Issue with maintaining variable state in Angular 7 service component

I currently have 2 components and a single service file in my Angular project, which consist of a login component and a dashboard component. The issue arises when I try to access the user data from the service file. In the login component, the user data i ...

Discovering the quantity of items with a specific value in Angular 8

I'm attempting to determine the number of objects with a status value of 'Served', which should yield 2. I'm unsure about the method I should use to achieve this. Any suggestions on which method would be best? {full_name: 'Jenny&a ...

Encountering issues in Angular 2 when attempting to pass data into root component through ng-content and binding. Objective: Creating a reusable form component

I currently have a .NET MVC application and I'm looking to integrate Angular 2 into it. The structure of my page is as follows: <html> <head>css imports and jquery imports</head> <body> <div> a bunch of table ...

Ways to verify if MatDialog is shown using a mock during an angular unit test

A unique feature of my current project involves utilizing a component that, upon a button click, triggers a pop-up to greet the user. To achieve this functionality, I have implemented Angular Material Dialog for handling the pop-up display. The specific co ...

What is the reason behind the equality comparison between number[][number] and number in TypeScript?

https://i.stack.imgur.com/htnkb.png type Test = number[][]; // The Test type will be inferred as 'number' based on the image above. Can you explain why number[] is considered an index signature type with a signature of 'number'? ...

Is there a way to selectively deactivate the routerLink attribute?

I am facing a challenge in my Angular 2 project where I am unable to disable the routerLink functionality successfully. Despite trying to intercept the click event on the 'click' event with 'event.preventDefault()' and 'event.stopP ...

Personalized ornamentation using TypeScript

Is there a way to access the variables of the class when using a decorator? @ExampleDecorator() export class UserController { private userData: string = "example"; } export const ExampleDecorator = (config: IConfigSettings) => (target: Object) =&g ...

Stop /Terminate the Angular 2 HTTP API request

Occasionally, the loading time for an http API call can be quite lengthy. However, even if we navigate to another component, the call still continues execution (which is visible in the browser console). Is there a method or approach that allows us to can ...