3

I want to navigate and pass some hidden parameters to an external link from the angular router.

Say I have an angular app running on www.demo.com and I want to navigate to www.xyz.com with some hidden parameters using angular router.

I tried using router.navigate() but I guess it only works within the application, not with external links.

Html

<a class="UserActions-editButton edit-button EdgeButton EdgeButton--tertiary" data-scribe-element="profile_edit_button" type="button" (click)="enterUrl($event)">
<span class="button-text">Enter Url</span>
</a>

Component

enterUrl(event:any){
    var final_url = 'www.xyz.com'
    this.router.navigate([final_url], { queryParams: {token: this.token}});
  }

Please suggest a solution. Thanks

User0706
  • 1,067
  • 1
  • 18
  • 34

2 Answers2

0

No, You can't send hidden params to any external link.

But below is the Use case for internal navigation within the Angular application.

IMO for your use case data property would help you to achieve your requirement.

const routes: RouterConfig = [
  {path : 'heroes', component : HeroDetailComponent, data : {some_data : 'some value'}}
];

So, You will get your content you passed like this -

this.route.data.subscribe(data => console.log(data));

PS: But as of my knowledge you can send only static data using data property.

The data property in the third route is a place to store arbitrary data associated with this specific route. The data property is accessible within each activated route. Use it to store items such as page titles, breadcrumb text, and other read-only, static data. You'll use the resolve guard to retrieve dynamic data later in the guide.

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
-1

Firstly, this.router.navigate just work only angular application. No way to do your request with it.

Have a solution in this case is use javascript to open new tab.

You can refer here: Open a URL in a new tab (and not a new window) using JavaScript

Dinh Duong
  • 297
  • 2
  • 10
  • It's not only about navigating to the external URL, it's about navigating with some hidden params – User0706 Jun 27 '18 at 04:48
  • `running on www.demo.com and I want to navigate to www.xyz.com` ??? you said, right? – Dinh Duong Jun 27 '18 at 06:15
  • And then if I no mistake you want to pass the token to `www.xyz.com`, is it correct? Firstly you should be understand about it, it not problem of angular. – Dinh Duong Jun 27 '18 at 06:18
  • I guess u didn't read the whole question. It says "app is running on www.demo.com and I want to navigate to www.xyz.com with some hidden parameters using angular router". And it is a question related to angular – User0706 Jun 27 '18 at 06:22
  • But the `this.router.navigate` just resolve the routing for angular app **only**. And then angular is just the framework that wrapper by javascript. Navigate to another `domain` is diff thing, why you want keep your mind is use `angular router` to do this. – Dinh Duong Jun 27 '18 at 06:26
  • I know router.navigate works with in app routing only. That's why I asked if there is any way to achieve what I want using angular router. And I'll be grateful if you can help me out with the issue I have rather than arguing on something which is irrelavant – User0706 Jun 27 '18 at 06:33
  • Ok I don't want to arguing or something like that, but like as my comment before, I surely no way to do with `angular router` and no way to go external link with hidden values (at least it's based on my experience). I will wait your update to get it. – Dinh Duong Jun 27 '18 at 06:39