Hello,
I have been blocking for three days on a problem that I cannot solve.
I tried several solutions that I could find on the forums but it did not change anything.
I am developing a PWA, I have two “menus
”, one for the desktop
version which is displayed just below the header and the second for the mobile
version which is displayed by clicking on “ion-menu-button
”.
To display the articles, the application must know what type of articles it should display, for adults or children.
Example, to see adult articles: https://www.example.com/articles
Example, to see children’s articles: https://www.example.com/kids/articles
You will notice that the “kids
” segment has been added.
All the sections have the same thing.
In the menu, I have a button that allows you to switch between adults and children regardless of the section.
The switch system works very well on the menu of the desktop version but not the menu for the mobile version.
The segment returns a value of “NULL
” in the “routerLink
” and even when I switch between modes the value does not change. When I debug and look at the logs, the value has changed and I can even display it next to the title of the link.
I use a “SegmentPipe” to return the correct value.
I noticed one thing, when the segment changes if I concat the variable « pages
»
this.pages = this.pages.concat(...this.pages, ...this.pages);
The new added values have the right segment.
Thanks for your help.
// app.components.html
...
<ion-menu-toggle auto-hide="false" *ngFor="let page of appPages">
<ion-item [routerLink]="page.url | segment | async"
[routerLinkActive]="'active'"
[routerDirection]="'root'">
<ion-icon slot="start" [name]="page.icon"></ion-icon>
<ion-label>
{{page.title | translate}} {{page.url | segment | async}}
</ion-label>
</ion-item>
</ion-menu-toggle>
...
import {Pipe, PipeTransform} from '@angular/core';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {trimSlashes} from '../shared/utils';
import {SettingsFacade} from '../store/settings/settings.facade';
@Pipe({
name: 'segment',
// pure: false
})
export class SegmentPipe implements PipeTransform {
segement$: Observable<string>;
constructor(private settingsFacade: SettingsFacade) {
this.segement$ = this.settingsFacade.segment;
}
transform(value: string): Observable<string> {
return this.segement$
.pipe(
map((segment: string) => {
return `/${trimSlashes(segment + value)}`;
})
);
}
}