Conceal multiple parameters within routing for added security

I have setup my Angular component with a button that triggers an event. Inside this event, I currently have:

this.router.navigate('page2')

While I am aware that query parameters can be passed inside the URL, I am faced with the challenge of passing a list of strings to the new page. Typically, if I had to open page2 with just one entity to query, I would use:

url.../page2/entity1

However, in my scenario, I need to send multiple entities (such as entity2, entity3, and entity4) to page2 without using query parameters since there could potentially be hundreds or even thousands of them!

So my question is, what is the most efficient way to pass these elements to another page using routing? I want to ensure that even if I pass multiple parameters without including them in the URL, I don't lose the results upon refreshing the page. Is there a solution for this?

Answer №1

According to the Angular documentation, you can utilize the NavigationExtras object to transmit supplementary data as state or queryParams. For more information, visit https://angular.io/api/router/NavigationExtras.

An object named extraParams can be used to input additional parameters.

import { Router, NavigationExtras } from '@angular/router';
  ...
constructor(private router: Router) { }

let extraParams: NavigationExtras = {
  state: {
      productId: selectedProductId
  } 
};

this.router.navigate(['/products/details'], extraParams);

These parameters remain hidden in the URL and can only be accessed on the target page using Router.

constructor(private router: Router) {
const currentState = this.router.getCurrentNavigation();
if (currentState && currentState.extras && currentState.extras.state) {
      let productId:string = console.log(currentState.extras.state.productId );
    } 
}

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

The automatic renewal of silent access tokens in Oidc client js fails due to the failure of the sliding expiration feature of the identity server authentication cookie

Working on an angular single-page application (SPA) that utilizes authentication through Identity Server 4 and OIDC client js. Encountering issues with the silent access token renew process. The expected behavior is for the access token to automatically r ...

Leveraging two variables in *ngIf

<ion-col size="12" *ngFor="let day of weekdays"> <h5>{{day | titlecase }}</h5> <ion-grid fixed> <ion-row> <ng-container *ngFor="let item of category.menu_items"> ...

Angular2: Issue encountered while processing click event

When I click a button on my client application, it sends a request to the server I created using Express. The request handler in the server simply logs 'Delete from server' every time the button is clicked. I am encountering these errors when cl ...

Compilation in TypeScript taking longer than 12 seconds

Is anyone else experiencing slow TypeScript compilation times when building an Angular 2 app with webpack and TypeScript? My build process takes around 12 seconds, which seems excessively slow due to the TypeScript compilation. I've tried using both ...

Integration of SSR is not possible in an ongoing Spartacus project

Recently, I attempted to integrate SSR mode into my existing Spartacus project using the following command: ng g @spartacus/schematics:add-ssr However, this action resulted in the following error message: ✅️ Added 'ts-loader' into devDep ...

When you subscribe to a forkJoin, you will receive an error notification

Trying to determine when all my observables have returned their values is a challenge I'm facing. Here's my approach after including import { Observable } from 'rxjs/Rx';: let observables:any[] = []; observables.push(this.getV ...

How to store property transformation in Redux/ngrx

I have the following setup someReducer.ts export interface State { someProp: MyModel; } // some action listeners .. // // export const getProp = (state: State) => state.someProp; selector.ts export const getProperty = createSelector(getState, f ...

Transferring an Image File from Angular 8 to a Spring Boot Application

Having trouble sending a file from my Angular 8 app to my Spring Boot server. I've tried using MultiPartFile and HttpServletRequest in Spring, among other methods, with no luck. I'm hoping someone can provide guidance on how to successfully retr ...

Confidently set up a proxy that is recursively nested and strongly typed

I have a collection of objects where I store various content for a user interface. Here is an example: const copy = { header: { content: 'Page Header' }, main: { header: { content: 'Content Subheader' }, body ...

Can you explain the functionality of this Angular CLI instruction?

Can you explain the function of this command in the Angular command line? npx ng g s weather --flat false Referenced in: Angular 6 for Enterprise Ready Web Applications, page 61 ...

Struggling with Angular CLI installation on Mac?

I've been trying to install Angular on my Mac's global directory, but I haven't been successful after multiple attempts. I've tested the following commands: npm install -g @angular/cli npm install -g @angular/cli@latest How to upgrad ...

Error in Typescript: The type 'string' cannot be assigned to the type '"allName" | `allName.${number}.nestedArray`' within the react hook form

Currently, I am tackling the react hook form with typescript and facing a challenge with my data structure which involves arrays within an array. To address this, I decided to implement the useFieldArray functionality. allName: [ { name: "us ...

Recording the details of an Angular project through the utilization of Compodoc

I am currently in the process of documenting my Angular + Typescript application using Compodoc. To install Compodoc, I utilized npm and executed the following command: 'npm install -g compodoc'. And included "compodoc": "./node_modules/ ...

Creating custom generic functions such as IsAny and IsUnknown that are based on a table of type assignability to determine

I attempted to craft a generic called IsAny based on this resource. The IsAny generic appears to be functioning correctly. However, when I implement it within another generic (IsUnknown), it fails: const testIsUnknown2: IsUnknown<any> = true; // iss ...

strange complications with importing TypeScript

In my Typescript projects, I frequently use an npm module called common-types (repository: https://github.com/lifegadget/common-types). Recently, I added an enum for managing Firebase projects named FirebaseEvent. Here is how it is defined: export enum Fi ...

Dependency on Angular's HTTP service inside a component

I've been experimenting with loading data from a static JSON file as part of my journey to learn angular templating. After some searching online, I came across a few examples. However, I want to steer clear of implementing a service until I have a be ...

How can I resolve the issue of "Errors detected in your package-lock.json" in NGRX?

I encountered some problems while trying to set up my Angular project in an NX workspace with NGRX and running it through Jenkins. After running npm install, I started getting errors. Has anyone else experienced errors like these after executing: nx updat ...

Rendering in Angular 2 is exclusively done through the use of arrow functions

Is Angular 2 only rendering using arrow functions, or am I missing something? this.service.getData(o).subscribe(res => { this.data = res.data this.view = res.view }); It actually renders my component, but this.service.getData(o).subscribe(functi ...

Manipulate classes by adding or removing them on click events in Angular

I am struggling to implement the angular ngClass for adding a class with a click event. Despite calling a function that should change the value of the "isExpandedConectivity" variable when clicking on the "li" element, it doesn't seem to work as expec ...

Troubleshooting Authorization Header Issue in Angular 5

I created an Interceptor to include an Authorization token in all HTTP Requests, but unfortunately it's not functioning as expected. I've double-checked my code and everything seems correct, so I'm wondering if there's something crucial ...