Angular sub-route is failing to activate

My current setup involves Angular routing along with the use of ngx-translate-router, and I've encountered an unusual issue with child routes. It's unclear whether this problem is connected to the translated router module I'm utilizing, but due to the complexity of the application, it's challenging to dissect.

The main issue appears to be that my routing functions only when the page is reloaded directly. When attempting to navigate using [routerLink]="['/admin', 'users']", there are no errors reported. The console displays the router traces, and while examining the router tree, I can see the component intended to load listed, yet it remains inactive.

// app.module.ts

const appRoutes: Routes = [{
    path: "",
    loadChildren: () => import("./auth/auth.module").then(m => m.AuthModule),
    data: {
        discriminantPathKey: "AUTHPATH",
        skipRouteLocalization: true
    }
}, {
    path: "admin",
    loadChildren: () => import("./admin/admin.module").then(m => m.AdminModule),
    data: {
        discriminantPathKey: "ADMINPATH",
        skipRouteLocalization: true
    }
}, {
    path: "",
    component: MainComponent,
    children: [{
        path: "",
        component: SidebarComponent,
        children: [{
            path: "",
            component: CitiesListComponent
        }, {
            path: "search",
            component: SearchComponent
        }, {
            path: ":cityId",
            component: CityComponent,
            children: [{
                path: "",
                redirectTo: "locations",
                pathMatch: "full"
            }, {
                path: "locations",
                component: LocationsListComponent,
                children: [{
                    path: ":locationId",
                    component: LocationComponent
                }]
            }]
        }]
    }]
}];

The subsequent loaded module is configured as follows

// admin/admin.module.ts

import { NgModule } from "@angular/core";

import { FormsModule } from "@angular/forms";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { SharedModule } from "../shared/shared.module";
import { CommonModule } from "@angular/common";
import { AuthModule } from "../auth/auth.module";
import { AdminRoutingModule } from "./admin-routing.module";
import { UsersService } from "./services/users.service";
import { DashboardComponent } from "./components/dashboard/dashboard.component";
import { NavigationComponent } from "./components/navigation/navigation.component";
import { UsersComponent } from "./components/users/users.component";
import { AdminComponent } from "./admin.component";


@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        NgbModule,
        SharedModule,
        AdminRoutingModule,
        AuthModule
    ],
    declarations: [
        AdminComponent,
        DashboardComponent,
        NavigationComponent,
        UsersComponent
    ],
    providers: [
        UsersService
    ],
    exports: [
        AdminRoutingModule
    ]
})
export class AdminModule {
}

And here is the routing module it imports

import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { TranslateModule } from "@ngx-translate/core";
import { LocalizeRouterModule } from "@gilsdav/ngx-translate-router";
import { DashboardComponent } from "./components/dashboard/dashboard.component";
import { AdminComponent } from "./admin.component";
import { UsersComponent } from "./components/users/users.component";

const routes: Routes = [{
    path: "",
    component: AdminComponent,
    children: [{
        path: "",
        component: DashboardComponent,
        pathMatch: "full"
    }, {
        path: "users",
        component: UsersComponent
    }]
}];

@NgModule({
    imports: [
        TranslateModule.forChild(),
        RouterModule.forChild(routes),
        LocalizeRouterModule.forChild(routes)
    ],
    exports: [
        RouterModule,
        LocalizeRouterModule
    ]
})
export class AdminRoutingModule {}

How can I pinpoint where the issue with my routing lies? I attempted debugging by manually altering the compiled JavaScript files, but unfortunately, this method proved ineffective.

Answer №1

The problem seems to be originating from the npx-translate-router module. After some troubleshooting, I made a change to the GilsdavReuseStrategy by setting it to return false within the shouldReuseRoute method, and miraculously, the routing started functioning properly once more. There were some side effects, but at least the page transitions worked.

This issue should be brought up with the creator of the package.

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

Step-by-step guide on incorporating an external JavaScript library into an Ionic 3 TypeScript project

As part of a project, I am tasked with creating a custom thermostat app. While I initially wanted to use Ionic for this task, I encountered some difficulty in integrating the provided API into my project. The API.js file contains all the necessary function ...

the behavior subject remains static and does not update

Working on setting my language in the BehaviorSubject with a default value using a LanguageService. The service structure is as follows import {Injectable} from '@angular/core'; import * as globals from '../../../environments/globals'; ...

Utilizing Material Design Icons within Angular 4: A Step-by-Step Guide

I'm looking to integrate the icons available on into my angular 4 project. However, the website's instructions only cover how to do this in Angular 1.x () Can someone guide me on how to include Material design icons so that I can use them like ...

What is the reason behind Typescript raising an error when attempting to compare two boolean variables with different values (true and false)?

In the screenshot below, you can see that we are encountering a peculiar error when attempting to compare a boolean variable with true. This condition will always return 'false' since the types 'false' and 'true' have no over ...

The silent refresh functionality is currently not functioning as expected in Angular's OAuth OIDC implementation

In my Angular SPA, I am attempting to silently refresh the access token. The authentication with ADFS has been successfully completed and everything is functioning properly. Below is the configuration that I have implemented: oauthService.configure({ ...

Typescript Server Problem: Critical Error - Mark-compacts Inefficiently Close to Heap Limit, Allocation Unsuccessful - JavaScript Heap Exhausted

Whenever I run my CRA project, I consistently encounter this error in my console. It seems to be related to the typescript server. Is there a solution for this issue? 99% done plugins webpack-hot-middlewarewebpack built preview 7c330f0bfd3e44c3a97b in 64 ...

Execute the function right away and then at regular intervals of X seconds

Need help with Angular 7 function call timing checkData(): Observable<string> { return this.http.get('') .pipe( map(res => { let result; result = { packageNumbe ...

CSS-WHAT Package for Angular Update - Enhance Your Styles!

In my Angular setup, the configurations are as follows: _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | ...

Searching Local JSON Data in Ionic 4 with a Filter Input Bar

My current challenge involves filtering local JSON data in my Ionic project. Despite referencing other resources, I am unable to filter or display filtered items on the ngx-datatable. I suspect the issue may lie either in the filterItems function implement ...

When utilizing Rx.Observable with the pausable feature, the subscribe function is not executed

Note: In my current project, I am utilizing TypeScript along with RxJS version 2.5.3. My objective is to track idle click times on a screen for a duration of 5 seconds. var noClickStream = Rx.Observable.fromEvent<MouseEvent>($window.document, &apos ...

sending arguments to angular directive

It was causing me some concern to see the number of global Angular change detections triggered every time an event occurs. That's why I stumbled upon Angular 2 runOutsideAngular still change the UI and decided to implement the 'OutSideEventHandle ...

Creating dynamic charts using Angular 7 with Chartjs and mapping JSON data

Struggling to map JSON Data for a Bar-Chart display. The desired final Array should be: [883, 5925, 17119, 27114, 2758]. Seems like the Array I'm trying to use for barChartData (dringlichkeitenValues[]) is empty. Apologies for my coding skills. Can so ...

How to trigger a subscription in RXJS only when another Observable is not true

Only emit subscription if the other observable is false. Check out this sample code: const loadingSubject$ = new BehaviorSubject<boolean>(false); const valueSubject$ = new BehaviorSubject<string>(''); valueSubject$ .pipe( // a ...

Advanced Typescript contains a parameter that specifies the type of callback function

Is it possible to create a function that is more typesafe than the current implementation? public addBusinessRule(targetProperty: string, dependentProperties: string[], callback: (dep0: any, dep1: any, ...)): void { // s ...

What is the syntax for defining a generic type in TypeScript when using the property name "type"?

Is there a way to declare a generic type GetAppActions where if T is equal to trigger, only the trigger data property is displayed, and vice versa? type GetAppActionType = 'trigger' | 'action' interface AppActionInputField {} type GetA ...

transmit information to a service using Angular 8

There are 4 multiselect dropdowns, and when I click on an event, I save the data array of objects in the same component. Now, I need to send this data to display it in another component. To achieve this, I am using a service. However, every time I send th ...

Issues with installing dependencies in Angular 2 through npm

While developing my Angular 2 application locally, everything was working smoothly. However, when I tried to deploy it to the server without the node_module folder and then did a npm install followed by a build, my app just kept showing "Loading..." withou ...

Issue regarding the Angular Material module

I recently added @angular/material to my project, using version @6.2.1. However, I encountered an error when trying to import this module in my app.module.ts file. The error message reads: "Module 'c:/Users/Rachana/Angular1/demo1/node_modules/@ang ...

Angular elements nested within each other are causing the ExpressionChangedAfterItHasBeenCheckedError

After conducting thorough research on this issue, I am now uncertain whether it is a bug or an error in my implementation. The problem arises with an element that utilizes a service to retrieve data and then passes it on to a child element. However, upon ...

Issues encountered when integrating ag-grid-react with typescript

Despite extensive searching, I am unable to find any examples of utilizing ag-grid-react with TypeScript. The ag-grid-react project does have TypeScript typing available. In my React app, I have installed ag-grid-react: npm i --save ag-grid ag-grid-react ...