What causes the appearance of the "?" symbol at the beginning of the URL and triggers a reboot of the app when moving through the absolute path?

I am facing an issue.

In my multi-module application with lazy loading, I encountered a strange behavior when trying to navigate between child lazy modules. Transition from top module to bottom child module works fine, but routing from one bottom child lazy module to another causes problems.

Here are some scenarios that work:

=> http://localhost:4200/#/op/services/ =>
=> http://localhost:4200/#/op/services/management/ =>
=> http://localhost:4200/#/op/services/management/edit/123

=> http://localhost:4200/#/op
=> http://localhost:4200/#/op/test/management/
=> http://localhost:4200/#/op/test/management/edit/321

And here is the problematic scenario:

http://localhost:4200/#/op/test/management/edit/321 =>
=> http://localhost:4200/#/op/services/management/edit/123

When I attempt this navigation, the URL starts with '?' and the app undergoes a full reload!

Surprisingly, whether or not a lazy module is loaded does not impact the issue at all.

This problem occurs inconsistently, sometimes the transition works just as intended! Despite attempting various combinations, I have been unable to resolve the issue.

Things I have tried include:

this.router.navigate([op/services/management/edit/${id}]);
this.router.navigate([/op/services/management/edit/${id}]);
this.router.navigate(['/op/services/management/edit/', id]);

this.router.navigateByUrl(op/services/management/edit/${id});
this.router.navigateByUrl(/op/services/management/edit/${id});

routerLink = "/op/services/management/edit/123"
routerLink = "op/services/management/edit/123"

I need help understanding why the route changes unexpectedly.

UPDATE.

Added simplified route configuration:

Base module:

const routes: Routes = [
  {
    path: '', loadChildren: './path/to/op.module#OperatorModule',
    data: {
      preload: false,
      base: true,
    },
  },
  ...
  ];

@NgModule({
  imports: [RouterModule.forRoot(
    routes,
    {
      useHash: true,
      preloadingStrategy: SelectivePreloadingStrategy,
    },
  )],
  exports: [RouterModule],
})
export class AppRoutingModule {}

Operator module containing inner lazy modules:

const routes: Routes = [
  {
    path: 'op',
    component: BasePage,
    canActivate: [AuthGuard],
    children: [
        {
            path: 'services/management',
            loadChildren: './services/services.module#ServicesModule',
            canActivate: [AuthGuard],
            data: {
              preload: true,
            },
        },
        {
            path: 'tests/management',
            loadChildren: './tests/tests.module#TestsModule',
            canActivate: [AuthGuard],
            data: {
              preload: true,
            },
        },
      ...
    ],
  },
];

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

Router modules for some of the inner modules:

For services:

const routes: Routes = [
  {
    path: '',
    data: {
        ...
    },
    pathMatch: 'full',
    component: ServicesPage,
    canActivate: [AuthGuard],
  },
  {
    path: 'edit/:id',
    data: {
      accessRole: [UserRole.USER, UserRole.ADMIN],
    },
    component: ServicePage,
    canDeactivate: [CanDeactivateGuard],
    canActivate: [AuthGuard, RoleGuard],
  },
  ....
];

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

For tests:

const routes: Routes = [
  {
    path: '',
    data: {
        ...
    },
    pathMatch: 'full',
    component: TestsPage,
    canActivate: [AuthGuard],
  },
  {
    path: 'edit/:id',
    data: {
      accessRole: [UserRole.USER, UserRole.ADMIN],
    },
    component: TestPage,
    canDeactivate: [CanDeactivateGuard],
    canActivate: [AuthGuard, RoleGuard],
  },
  ....
];

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

UPDATE!

I recently discovered a new reason for the problem. The issue arises when attempting to route using an HTML form. I have a CanDeactivate service warning about leaving the page, and even with this service disabled on the page, the window:beforeunload event still triggers on any form submission.

Although it's unclear how these elements are interconnected, I feel like I'm making progress towards solving the issue.

Answer №1

The route button originally had a default type of 'submit', but after changing it to type='button', everything worked perfectly!

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

Dealing with consecutive time period inquiries in Angular

My goal is to make 4 consecutive requests in Angular, and for some of these requests, I need to send multiple requests within this.myService.startAudit() until either the timer reaches 30 seconds or we receive a non-empty response. The issue with my curren ...

The :root selector has encountered a malfunction within the Angular component

I'm interested in experimenting with CSS variables in my Angular 11 component. <div class="main-content"> <a>Test Link</a> </div> Here is my app.component.css: div.main-content{ --main-color: red } a{ color: v ...

mat-sidenav is exempt from the fxFlex rules

Having trouble centering the content within . I've attempted various rules but nothing seems to be working. Interestingly, when I apply fxFlex rules to , everything falls into place perfectly. I've gone through trying to set rules for each elemen ...

The expanded interfaces of Typescript's indexable types (TS2322)

Currently, I am in the process of learning typescript by reimagining a flowtype prototype that I previously worked on. However, I have hit a roadblock with a particular issue. error TS2322: Type '(state: State, action: NumberAppendAction) => State ...

Using Angular template to embed Animate CC Canvas Export

Looking to incorporate a small animation created in animate cc into an angular template on a canvas as shown below: <div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:1014px; height:650px"> <canvas id="canv ...

Error exporting variables in NodeJS causing confusion

I'm currently in the process of transitioning a Meteor application from TypeScript to Javascript. While working on the server side, I've encountered some issues with the import/export code that functioned smoothly in TypeScript but now seems to b ...

Error in Typescript syntax within a CommonJS/Node module: Unexpected colon token found in function parameter

After validating the file with TS, there are no more errors. However, during runtime, I encounter an "Unexpected token ':'" error on any of the specified TS, such as immediately erroring on function (err: string). The following are my build and ...

The element 'stripe-pricing-table' is not a recognized property of the 'JSX.IntrinsicElements' type

I am currently trying to incorporate a pricing table using information from the Stripe documentation found at this link. However, during the process, I encountered an issue stating: "Property 'stripe-pricing-table' does not exist on type &ap ...

What is the substitute for <center> tag in AngularJS?

Error: Template parse errors: 'center' is not a recognized element: 1. If 'center' is supposed to be an Angular component, make sure it is included in this module. 2. To permit any element, add 'NO_ERRORS_SCHEMA' to the ' ...

Issue found in Angular 4.x Karma test: "FocusTrapFactory Provider Not Available"

My Angular v4.x project includes Angular Material 2.x and a modal login component using MdDialog. However, all of my tests are failing with the error: Failed: No provider for FocusTrapFactory! at injectionError... Here is a snippet from my login.compon ...

Ways to inform websocket client of authentication failure

Utilizing the (ws package) in Node.js to handle websockets, I leverage the "on upgrade" event to authenticate incoming clients based on a token provided as a URL parameter. Following the guide here, if the token is invalid/missing/expired, I utilize the fo ...

I encountered an unexpected obstacle while reloading my Next.js application with animejs. The error message reads: "SyntaxError: Unexpected token 'export'." This unwelcome occurrence took place during the

Encountering an error with animejs when reloading my Next.js app: An unexpected token 'export' is causing a SyntaxError. This issue occurred during the page generation process. The error originates from file:///Users/.../node_modules/animejs/lib ...

Overlap with upper picture formatting

I've been struggling to create an ion-card with two images: a main picture and a small book cover. Any ideas on how to achieve this? Note: The layout should have 2 images, one at the top and another as a small book cover. Check out this sample on St ...

"Learn the process of extracting information from a database and exporting it to a CSV file with Angular 2

Currently, I am facing an issue where I need to retrieve data from a database and export it to a CSV file. While I am able to fetch all the data successfully, I am encountering difficulty when trying to fetch data that is in object format as it shows up as ...

Angular Bounce Effect: Adding a Touch of Fun to Your

I'm utilizing the angular animation plugin ( https://www.npmjs.com/package/@angular/animations ) in my project. I am now looking to incorporate a bouncing effect when adding or removing items from an array. Below is the template snippet: <h2 *ngI ...

I want my Angular 2 application to redirect to the appropriate page when a user who is logged out attempts to access a page that requires them to be logged in

When a user is logged out in Angular 2 router and they try to navigate to a page that requires them to be logged in, I need the app.ts file to redirect them. I am utilizing typescript along with angular 2. Oddly enough, the redirection works for certain ...

Searching for true values in MongoDB using the query syntax can be challenging

I have a question that might be a bit embarrassing, but I need help with rendering a user search based on both location and date. Our profile object is structured like this: availability: { monday: { type: Boolean, default: false }, tuesday: { type ...

Setting up React Context API with TypeScript: A Step-by-Step Guide

I recently updated my app.js file to app.tsx for improved functionality. However, I encountered an error with the current value. app.tsx import React, { createContext, useState } from "react"; import SelectPage from "./pages/select/select& ...

Navigating with Angular: How to pass route parameters within the same component?

Issue: There seems to be a problem with the link selection as both are getting selected when I click on one. However, the individual links display correctly. https://i.stack.imgur.com/gZWqD.png I believe that clicking on a link doesn't refresh the e ...

The component 'Form' cannot be utilized in JSX because its return type, 'ReactNode', is not a valid JSX element

I'm facing an issue with my Next.js application written in TypeScript after updating react-bootstrap. After the update, I am encountering the following error when attempting to use the Form component from react-bootstrap: react-bootstrap: ^2.10.3 @typ ...