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

Typescript libraries built specifically for unique custom classes

I am currently exploring the most effective method for creating a class library in Typescript and deploying it to NPM along with a definitions file. The classes within the library serve as models that are utilized by multiple RESTful services. Some of the ...

Issue: NullInjectorError: R3InjectorError(AuthorModule)[ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelper]:

While I am going through a tutorial on the abp framework, I encountered an error with the Author route that says "ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AuthorModule)[ScrollbarHelper -> ScrollbarHelper -> ScrollbarHelp ...

Creating Excel documents using Angular and XLSX template generator

In my Angular application, I am utilizing the XLSX library to manipulate an Excel file. The file I start with is encoded in base64 format, so my first task is to decode it, make some changes to specific cells, and then save the modified file back in base64 ...

Redux-toolkit payload does not recognize the specified type

While working on my project, I encountered an issue when using redux-toolkit. I have created the following reducer: setWaypointToEdit: (state, action: PayloadAction<WaypointToEditPayload>) => { let gridPolygonsData: GridPolygonsData; const { ...

Issues arise when attempting to override attributes within the HTML of a parent component in Angular

Why does overriding an attribute in a child class that extends from another not work as expected? Here's a made-up scenario to simplify the issue: Parent class file: gridbase.component.ts import { Component, OnInit } from '@angular/core'; ...

The storybook is struggling to find the correct builder for the Angular project

I have set up a complex angular workspace with multiple projects. Within the main angular workspace project directory, I have two folders - one for the project application named eventric, and another for a library called storybook. https://i.stack.imgur.c ...

Display a semantic-ui-react popup in React utilizing Typescript, without the need for a button or anchor tag to trigger it

Is there a way to trigger a popup that displays "No Data Found" if the backend API returns no data? I've been trying to implement this feature without success. Any assistance would be greatly appreciated. I'm currently making a fetch call to retr ...

Navigating through JSON in Angular

I am facing an issue with looping through my JSON data to extract the data output. While I can successfully loop through {GET_PUT_AWAY_Inspection_F:{.....}}, attempting (this.myData.GET_PUT_AWAY_Inspection.data) results in an error stating it is undefined. ...

Dealing with dynamic meta tags in Angular for server side rendering (SSR): Best practices and tips

Currently, I am attempting to display dynamic data in the title, meta, and description tags of an Angular application using the nguniversal package. However, despite my efforts, I have not been able to locate comprehensive documentation on how to achieve t ...

By default, all groups in the Kendo UI Angular 2 Grid are collapsed

Just started using the new Kendo UI for Angular 2 Grid and I have a question - is it possible to collapse all groups by default when grouping data? I noticed there is a method called collapseGroup(), but it's unclear how to use it or if there's ...

Having trouble performing nested queries with RxJS 6 and the expand operator in Angular, Firebase, and Observables?

I came across a query on Stack Overflow that helped me fetch a random item from a Firebase collection in my Angular 9 app using AngularFire. While the solution works perfectly and gives me the desired output most of the time, there's an issue when th ...

When using nodejs with sqlite3, the first callback parameter returns the class instance. How can this be resolved in order to prevent any issues?

Exploring a TypeScript class: class Log { public id: number; public text: string; construct(text: string){ this.text = text; } save(){ db.run( `insert into logs(text) values (?) `, this.text, ...

Why is my Angular Reactive form not retrieving the value from a hidden field?

I've encountered a problem where the hidden field in my form is not capturing the product id unless I manually type or change its value. It consistently shows as "none" when submitting the form. TS https://i.stack.imgur.com/W9aIm.png HTML https://i. ...

What sets apart the browser/tab close event from the refresh event?

Can you help me understand the difference between a browser/tab close event and a refresh event? I've been researching this on Stack Overflow, but I'm still having trouble with it. My goal is to be able to log out a user through a server call whe ...

Design buttons that are generated dynamically to match the style

I have a challenge in styling dynamically generated buttons. I've developed a component responsible for generating these dynamic buttons. const TIMER_PRESETS: Record<string, number> = { FIFTHTEENSEC: 15, THIRTYSEC: 30, FORTYFIVESEC: 45, ...

Is there a way to export a specific portion of a destructuring assignment?

const { a, ...rest } = { a: 1, b: 2, c: 3 }; If I want to export only the rest object in TypeScript, how can I achieve that? ...

Incorporating Angular: A guide to removing a specific element from an HTML array using line breaks

For instance, here is a screenshot of an example: https://i.stack.imgur.com/UlP23.png In the section where I labeled "I want to go down a line", I have an array containing errors related to usernames and passwords. This is how the component.ts file looks ...

Updating Values in Nested Forms with Angular Reactive Form

I have been grappling with a form setup that looks something like this: itemEntities: [ {customisable: [{food: {..}, quantity: 1}, {food: {..}, quantity: 5}]}, {customisable: [{food: {..}, quantity: 0}]}, ] My challenge lies in trying to u ...

Transfer highlighted checkboxes between two containers. Any deselected checkboxes in the second container should also be removed from the initial container

I have successfully populated the necessary checkboxes within a single div element. Furthermore, I have been able to save the selected checkboxes to an object. I am interested in learning how to display this object (checkboxes) in another div. Additional ...

What causes the session storage to be accessed across various browser sessions?

Scenario While working on an application, I discovered an intriguing behavior in Chrome 62 on Windows 10 related to defining values in sessionStorage. Surprisingly, changing a value in one tab affected other tabs that shared the same key. Initially, I b ...