When accessing an Angular 7 page directly through the URL in the browser, it becomes unresponsive. However, the page works perfectly fine when navigating

I've been tackling a poorly developed Angular 7 legacy application and encountering a bizarre issue. There's a component that requires a parameter for email verification, but when the URL is visited directly, it doesn't function as expected. Strangely enough, manually navigating to the link with a hardcoded ID using an anchor tag works fine. I've investigated all routes, guards, and redirections, but can't seem to figure out why this odd behavior is happening.

-- app.component.ts
--- home.component.ts
---- verify.component.ts

The app component contains the router outlet for components, while the verify component is nested within the home component. I even tried placing the router outlet in the home component, but saw no change. Interestingly, the login and register components nested inside the home component folder work without any issues when accessed directly.

Here is the routing for the home module:

   const homeRoutes: Routes = [
  { path: '', redirectTo: 'index', pathMatch: 'full' },
  { path: 'index', component: HomeComponent },
  { path: 'login', loadChildren: './login/login.module#LoginModule' },
  { path: 'register', loadChildren: './register/register.module#RegisterModule' },
  { path: 'verify/:id', loadChildren: './verify/verify.module#VerifyModule' }]

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    PaginationModule,
    ModalModule.forRoot(),
    RouterModule.forChild(homeRoutes),
    NgxSummernoteModule,
    Daterangepicker,
    NgxDropzoneModule,
    ShareModule,
    TooltipModule.forRoot(),
  ],
  
  declarations: [HomeComponent],
  providers: [],
  bootstrap: [HomeComponent]
})
export class HomeModule { }

Here is the routing for the verify module:

const verifyRoutes: Routes = [
  { path: "", component: VerifyComponent },
];
@NgModule({
  imports: [
    CommonModule,
    PaginationModule,
    FormsModule,
    ModalModule.forRoot(),
    RouterModule.forChild(verifyRoutes),
  ],
  declarations: [VerifyComponent],
  providers: [DataService, NotificationService],
})
export class VerifyModule {}

Here is the app module routing:

 const appRoutes = [{ path: 'home', loadChildren: './home/home.module#HomeModule' }]
@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    CookieModule.forRoot(),
    FormsModule,
    HttpModule,
    RouterModule.forRoot(appRoutes, { useHash: true, enableTracing: true }),
    SlimLoadingBarModule.forRoot(),
    PaginationModule.forRoot(),
    BrowserAnimationsModule,
    ReactiveFormsModule,
    ModalModule.forRoot(),
    BsDropdownModule.forRoot(),
    ShareModule,
  ],
  providers: [
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

It's been several days and I'm still stuck on this issue. I've tried multiple solutions, but this one has me puzzled because when accessing the URL directly, Chrome freezes and eventually prompts that the page is unresponsive. Seeking guidance from the SO community. Thank you.

Answer №1

Reorganize the route by moving the :id variable to the component block:

  { path: 'register', loadChildren: './register/register.module#RegisterModule' },
  { path: 'verify', loadChildren: './verify/verify.module#VerifyModule' }]
const verifyRoutes: Routes = [
  { path: ":id", component: VerifyComponent },
];

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

There was an unexpected error: Module 'C:Users... ode_modules@angular-devkituild-angularsrcdev-server' could not be located

Struggling to get my Angular project up and running on a different system. I've copied all the necessary files (hopefully) but when I attempt to run the project using ng serve, it throws this error: An unhandled exception occurred: Cannot find module ...

How to Maintain Default Styling in Next.js with Material UI When Disabling Accordion Feature

I am currently working on a project using Next.js and incorporating Material UI for the user interface elements. One particular challenge I am facing is with an Accordion component that needs to be disabled under specific conditions, but still appear witho ...

Running NG BUILD from Gulp can be done using either child-process.spawn or by disabling all output in child-process.exec

Have you come across a similar question like this Call "ng build" from inside a gulp task? I have found a way to successfully build Angular using Gulp in order to prevent overflowing the output buffer. Here's how I achieved it: const child ...

efficiently managing errors in a Nest Jest microservice with RabbitMQ

https://i.sstatic.net/sUGm1.png There seems to be an issue with this microservice, If I throw an exception in the users Service, it should be returned back to the gateway and then to the client However, this is not happening! The client only sees the de ...

ReactJS tweet screenshot capture

Currently seeking a solution to capture a tweet screenshot, store it in a PostgreSQL database, and display it on my ReactJS webpage using Typescript. I have been utilizing react-tweet-embed for displaying the tweet, but now I require a method to save the i ...

A guide on displaying an Angular Component within a Thymeleaf page

Currently, I am faced with the task of integrating Angular and Thymeleaf. This is necessary because I have developed a dynamic graph using Angular and now need to incorporate it into an existing project that utilizes Thymeleaf. Are there any simplified m ...

What are the steps to configure JSS in a TypeScript/NextJS application?

Trying to set up a basic web app using React, TypeScript, NextJS, and Material-UI has been quite the challenge. The main issue I am facing revolves around styling within my project. To better illustrate my problem, I have created a CodeSandbox environment. ...

Form control identifier and input field name

I am currently developing a custom input feature for my application. One of the functionalities I want to include is auto-completion, and in my research, I found out that certain conditions need to be met for it to work: In order to enable auto-completi ...

Creating a responsive d3 gauge chart: A step-by-step guide

Need assistance resizing the d3 gauge chart. Check out the Stackblitz code for reference. I've attempted the following: .attr("preserveAspectRatio", "xMinYMin meet") as well as window.addEventListener("resize", this.draw); ...

Unit testing component in Ionic 2 with Ionic's specific markup and elements

Within my Angular 2 component for an Ionic 2 app, I utilize Ionic's markup as shown below: <ion-card> <h3>{{ rawcontent.name }}</h3> <p *ngIf="rawcontent.description">{{ rawcontent.description }}</p> </ion-car ...

Error in TypeScript not being caught in React due to incorrect type detection

Could you assist me in grasping the workings of TypeScript? I am currently trying to learn it but am struggling with understanding certain behaviors. Example 1: The issue lies in the type errors not being detected, please refer to the commented message wi ...

TS interfaces: Understanding the distinction between optional and mandatory properties

In this example, I am demonstrating TypeScript interfaces in a simple way: interface A: { id: number; email: string; } interface B extends A { login: string; password: string; } My goal is to have certain requirements when creating objects fr ...

Having trouble with @typescript-eslint/member-ordering feature not functioning properly?

Ensuring a precise ordering in TypeScript classes is my goal, with a specific emphasis on enforcing alphabetical order within groups. To achieve this, I am refering to the following documentation: Shown below is the member-ordering configuration extracte ...

Utilize the parameters from the config.json file within the application

We've integrated the Google Maps API into our project and have generated a key for it. Currently, this key is hardcoded in one of our module files. However, we want to enhance security by moving this key into the config.json file. This way, when we pu ...

The Angular build is unsuccessful due to the presence of components from a separate Angular project

Whenever I execute ng build project1 --prod, the build fails and displays this error message: ERROR in : Cannot determine the module for class MyComponent in .../project2/app/my.component.ts! Add MyComponent to the NgModule to fix it.. Although the sol ...

"Retrieve the x-coordinate position of a box within a specific div using

https://i.sstatic.net/68yeF.jpg https://i.sstatic.net/ZCrxZ.jpg Is there a way for me to move the box within the gray area? <div id="timeline"> <div cdkDragBoundary="#timeline" ...

Exploring how to traverse a <router-outlet> within its container

I am attempting to switch the active component within a from its parent. After observing how Ionic achieves this, I believe it should resemble the following (simplified): @Component({ template: '<router-outlet></router-outlet>' } ...

Is it necessary to unsubscribe from multiple switchmaps?

Consider the following scenario: Should I implement an unsubscribe in each instance of switchMap? And is it necessary to include a takeUntil after every switchMap operation? this.sharedSrv.postDetail.pipe( switchMap(post => { if (post) { th ...

Breaking down types in Typescript: Extracting individual types from an object containing multiple objects

Having a query: const queries = { light: { a... b... }, dark: { a... b... c... d... }, The react element requires a colors parameter that corresponds to one of the themes in the above object, with each theme containing a un ...

Encountering a Validation Error while Creating a Progressive Web App using Ionic CLI

I'm trying to build a simple PWA app using the IONIC Framework, but have been struggling to make it work. I am still new to Ionic and have followed various tutorials from different sources without success. If you want to check out the tutorials I&apo ...