Query parameters with virtualTree flag enabled #3567
-
Hi everyone I defined a navigation node with I followed the guide in this link also to sync the browser URL with the inner micro frontend URL. I applied some modifications depending on my needs, but everything seems to work fine. However, I cannot find the way to pass query parameters to the Angular application. Here I paste my current code snippets: Navigation node{
pathSegment: 'angular-test-app',
label: 'Angular Test App',
viewUrl: '/angular/test-app',
virtualTree: true
} Luigi navigation service in Angular appimport { Injectable, OnDestroy } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { linkManager } from '@luigi-project/client';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';
@Injectable({ providedIn: 'any' })
export class LuigiAutoNavigationService implements OnDestroy {
private destroy$ = new Subject<void>();
private initialized = false;
private urlRoot: string;
constructor(private router: Router) { }
ngOnDestroy(): void {
this.destroy$.next();
}
initializeForFeature(featureRoot: string): void {
if (this.initialized === false) {
this.urlRoot = featureRoot.startsWith('/') ? featureRoot : `/${featureRoot}`;
this.router.events
.pipe(
takeUntil(this.destroy$),
filter(ev => ev instanceof NavigationEnd && ev.url.startsWith(this.urlRoot)),
)
.subscribe(ev => {
linkManager()
.fromVirtualTreeRoot()
.withoutSync()
.navigate((ev as NavigationEnd).url.replace(this.urlRoot, ''));
this.initialized = true;
});
}
}
} I tried to hard code the query parameter just for test on the browser URL by writing What am I doing wrong? Can you help me, please? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @pietro-ditommaso, On the one hand we have Luigi's node params with a prefix before to get the node params, like in your url
You can add node params or you can navigate with params. On the other hand there are the regular query parameters like
Sorry for the late answer and please let me know if it helps. Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi @JohannesDoberer, I applied your suggestion about the first type of query parameters, the node params, and it actually worked. Although, what I imagined about the query parameters prefixed with This is an example of what I mean: {
pathSegment: 'angular-test-app',
label: 'Angular Test App',
viewUrl: '/angular/test-app',
virtualTree: true
} When I navigate to the following in url in the browser Basically, after your answer, I wrote something like the following snippet: private getIdParam(): number {
const nodeParams = getNodeParams();
return this.activatedRoute.snapshot.queryParamMap.get('id') || nodeParams['id'];
} Just to explain the reason why I wasn't able to make my code work before. Thank you very much for you help! |
Beta Was this translation helpful? Give feedback.
Hi @pietro-ditommaso,
first for clarification.
There are two types of query parameters in Luigi.
On the one hand we have Luigi's node params with a prefix before to get the node params, like in your url
http://localhost:4321/angular-test-app/details?~id=5
.You can add node params or you can navigate with params.
On the other hand there are the regular query parameters like
http://localhost:4321/angular-test-app/details?id=5
without any prefix.These params are called coreSearchParams with getter and setter for the luigi client.
Regarding security reasons it is necessary to set clientP…