Angular2 routing directs me to a different URL path

In my Angular2 web application, I have set up the following routes: '', '/app', '/login', '/signin', '/validate', '/error', '**':

I've defined a route configuration in app.router.ts:

import { Routes } from '@angular/router';
import { ErrorComponent } from './error/error.component';

export const ROUTES: Routes = [{
   path: '', redirectTo: 'login', pathMatch: 'full'
  }, {
    path: 'app',   loadChildren: () => System.import('./layout/layout.module')
  }, {
    path: 'login', loadChildren: () => System.import('./login/login.module')
  }, {
    path: 'signin', loadChildren: () => System.import('./signin/signin.module')
  }, {
    path: 'validate', loadChildren: () => System.import('./validate/validate.module')
  }, {
    path: 'error', component: ErrorComponent
  }, {
    path: '**',    component: ErrorComponent
  }
];

Only the '/validate' route needs to collect query parameters. Refer to the Validate module and component:

export const routes = [
  {path: '', component: Validate}
];

@NgModule({
  declarations: [
    // Components / Directives/ Pipes
    Validate
  ],
  imports: [
    CommonModule,
    FormsModule,
    RouterModule.forChild(routes),
  ]
})
export default class ValidateModule {
  static routes = routes;
}

----------------

import { Component, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';

import { UsersService, UserDTO } from 'cest/ts';

@Component({
  selector: '[validate]',
  templateUrl: './validate.template.html',
  encapsulation: ViewEncapsulation.None,
  styleUrls: ['./validate.style.scss'],
  providers: [ UsersService ]
})
export class Validate implements OnInit, OnDestroy {

  private id: string;
  private token: string;

  constructor(private router: Router, private route: ActivatedRoute, private userService: UsersService) { }

  ngOnInit():void {
    this.sub = this.route.queryParams.subscribe(params => {
      this.id = params['id'] || undefined;
      this.token = params['token'] || undefined;
  }

  ngOnDestroy() {
    this.sub.unsubscribe();
  }
}

I am encountering an issue with how the router is trying to locate the correct module/component.

The problem arises when trying to access the URL:

http://localhost:3002/validate?id=am9yZGkxMEBsaXZpbmctZGlnaXRhbC13YXkuY29t&token=Ra8i4mrGbz1tf9y9vJHLAd-TKHNH0Ig8o699jXU1YU4%3D-
.

Despite setting this URL with query parameters id and token, the Angular2 router redirects it to:

http://localhost:3002/validate?id=am9yZGkxMEBsaXZpbmctZGlnaXRhbC13YXkuY29t&token=Ra8i4mrGbz1tf9y9vJHLAd-TKHNH0Ig8o699jXU1YU4%3D-#/login
.

The final URL ends up adding #/login to the initial one.

Any suggestions?

Answer №1

To configure the validation path for your app module, follow these steps:

{
    path: 'validate/:id/:token', loadChildren: () => System.import('./validate/validate.module')
}

After setting up the path, remember to verify it.

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

What is the best way to transfer an object from the view to the controller in AngularJS and ASP.net MVC

How to pass an object with a specific amount of data from the View to the Controller using ASP.net MVC and AngularJS VIEW var Person = {}; Person.IdPerson = 69425; Person.Year = new Date().getFullYear(); $http.post('/API/Update_Person', { para ...

What is the best way to modify the underline style of a tab in Material UI?

I'm trying to customize the underline of: https://i.stack.imgur.com/J2R1z.png Currently, I am using material ui version 4.12.3 The code snippet for generating my tabs is below: function renderTabs(): JSX.Element { return ( <Tabs className={cla ...

How to set up Angular 5 with Express

What is the best way to add Angular 5 to an existing Express project? Below are my files: https://i.stack.imgur.com/DPgMs.png Package.json: https://i.stack.imgur.com/iVVxA.png I am looking to integrate Angular 5 into this express project and develop t ...

The object in an Angular 11 REACTIVE FORM may be null

I am looking to incorporate a reactive form validation system in my application, and I want to display error messages based on the specific error. However, I am encountering an error that says: object is possibly 'null'. signup.component.html &l ...

Tips for executing multiple asynchronous calls simultaneously within a nested map function

I am facing a scenario where I have an object with nested arrays of objects which in turn contain another set of nested arrays. To validate these structures, I have an asynchronous function that needs to be executed concurrently while awaiting the results ...

Using generics in Typescript, transform an array of strings into various types and values

Enhanced with coding norms I have obtained an array of fruit values: const fruitsArray = ["apple", "banana", "peach"] as const; Utilizing this array as a foundation, I generated types and values in the following manner: type ...

Having trouble triggering a change event within a React component?

I'm working on a straightforward react-component that consists of a form. Within this form, the user can search for other users. To ensure the form is valid, there needs to be between 3 and 6 users added. To achieve this, I've included a hidden ...

What steps can be taken to troubleshoot the npm start problem?

I am encountering the error shown below: https://i.stack.imgur.com/jqmcF.png This issue is present on Windows but not on Linux. Which dependency do I need to install? I can't seem to locate the Color npm dependency. ...

Using TypeScript import statements instead of the <reference path...> in an ASP.NET Core web application: A step-by-step guide

Understanding the Setup I initially had a functional TypeScript Hello World in my ASP.NET Core Web application. To compile TypeScript, I used the NuGet package "Microsoft.TypeScript.MSBuild" Version="4.4.2" along with a tsconfig.json f ...

The error message "Property does not exist on type Object from subscribe" indicates that

When using forkJoin to make multiple http calls, I encountered the error error TS2339: Property 'data' does not exist on type 'Object' forkJoin(this.userservice.getUser(), this.userservice.getDashboard()).pipe( map(([userData, dash ...

Utilize dependency injection or define dependencies with the following tags: 1) ionic

I am facing confusion about whether to inject a dependency or declare it in the constructor function. Here is an example: import { DOCUMENT } from '@angular/common'; import { ElementRef } from '@angular/core'; constructor(private el ...

Zod data structure featuring optional fields

Is there a more efficient way to define a Zod schema with nullable properties without repeating the nullable() method for each property? Currently, I have defined it as shown below: const MyObjectSchema = z .object({ p1: z.string().nullable(), p2 ...

Is there a way to verify useFormik functionality while the form is being submitted?

Below is the implementation of the Form component which utilizes the useFormik hook. While the component fulfills all my requirements, I encounter challenges when it comes to testing, especially during form submission. Form.tsx import { TextField, But ...

What is the connection between tsconfig.json and typings.json files?

I recently acquired a .NET MVC sample application that came with Angular2-final. Within the project, I noticed a typings.json file at the root and a tsconfig.json file in the ng2 app directory. What is the connection between these two files? Is this the mo ...

Display various react components based on the value of the property

I am in the process of creating an input component in ReactJs with typescript. The input can vary in types such as text, date, select, or textarea. Depending on the type provided, the displayed control will differ. For example, if set to text, <input t ...

How can one effectively outline the structure of a document within firestore?

Currently, I am enclosing my calls to Firebase within a function so that I can specify the return type within the function. This allows me to define the type of data being retrieved from a document. However, TypeScript complains if you do not convert the F ...

The routerlink feature consistently directs back to the default page

I am facing an issue where my routerlink does not redirect me to the correct path in app.routes.ts when clicked. Even though the routerlinks are set as 'user/teams' and 'user/dashboard' respectively. I can access the pages by directly ...

The absence of Index.ts in the TypeScript compilation cannot be resolved by simply including it

Upon integrating @fireflysemantics/slice into my Angular project, I encountered the following error: ERROR in ./node_modules/@fireflysemantics/slice/index.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: /home/ole/Temp/fs ...

The Delicacy of Ionic Date and Time

I'm currently working with Ionic 6 and Angular 14. Has anyone found a way to adjust the sensitivity of the Ionic Time Picker? The scrolling speed is too fast, making it challenging to select the correct hour/minute. https://ionicframework.com/docs/a ...

The mat-table fails to populate with data retrieved from the rest service

I have successfully fetched an array from my REST service and displayed some information from the response on the page. However, I am facing issues populating my mat-table and I'm unsure of the cause. The mat-table was functioning properly in the past ...