Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Angular how to route with parameters without changing the URL

TL;DR; I want to route to a page with parameters without the URL indicating underlying data.

I have 2 components. Component A & B. What I'd like to achieve is route to B but I need some paramteres from A. I know i can route to B by setting route like this [/B:parameter]. My problem is that it's changing the URL from localhost:4200/b to something like localhost:4200/b=?parameter. I'd like to hide parameter from users as it's:

-one: not relevant to them
-two: may contain sensitive business logic &/or data.

Currently I just set a constant to the appropriate state and read it on B's onInit but that feels very unelegant, and there should be a better, more elegant way to do things. Quite frankly it works well but I don't like it. How should I approach it?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Short answer: Passing data in route while navigate.

Explanation: You can found the data parameter in Route document (https://angular.io/api/router/Route)

Example: In routing module:

path: 'auth', component: AuthComponent, data: { type: 'admin' }

In AuthComponent you able to take the type data by using ActivateRoute

  constructor(
    private activatedRoute: ActivatedRoute
  ) {
    this.type = this.activatedRoute.snapshot.data.type;
  }

So you can ask: How to dynamically passing data while routing? Please check it out: Send data through routing paths in Angular

about 4 years ago · Juan Pablo Isaza Report

0

You can change the browser url without triggering any navigation by using e.g:

window.history.replaceState(undefined, '', '#newdata');

See: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState

But be really careful with that!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!