I have an Ionic project setup using the tabs template. Here is my issue: I have an Activity tab that will have 3 buttons on the page:
- Friends
- Near Me
- Global
When the page first load it will show a list of post for friends, when I click on the Near Me buttons it should replace the friends post with near me posts. this works great. When I click back on Friends, it does not change the content on the page. The URL changes, but the content does not.
tabs.router.module.ts:
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'activity',
outlet: 'activity',
component: ActivityPage,
children: [
{
path: 'friends',
outlet: 'friends',
component: FriendsComponent
},
{
path: 'nearme',
outlet: 'nearme',
component: NearMeComponent
},
{
path: 'global',
outlet: 'global',
component: GlobalComponent
}
]
},
{
path: 'about',
outlet: 'about',
component: AboutPage
},
{
path: 'contact',
outlet: 'contact',
component: ContactPage
}
]
},
{
path: '',
redirectTo: '/tabs/(activity:activity/(friends:friends))',
pathMatch: 'full'
}
];
activity.page.html:
<ion-toolbar color="primary">
<ion-segment class="tabs" [(ngModel)]="page">
<ion-segment-button class="tab-label" value="friends" (click)="selectFriends()" margin-start>
Friends
</ion-segment-button>
<ion-segment-button class="tab-label" value="near_me" (click)="selectNearMe()">
Near Me
</ion-segment-button>
<ion-segment-button class="tab-label" value="global" (click)="selectGlobal()" margin-end>
Global
</ion-segment-button>
</ion-segment>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-router-outlet name="friends"></ion-router-outlet>
<ion-router-outlet name="nearme"></ion-router-outlet>
<ion-router-outlet name="global"></ion-router-outlet>
</ion-content>
activity.page.ts:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-activity',
templateUrl: 'activity.page.html',
styleUrls: ['activity.page.scss']
})
export class ActivityPage implements OnInit {
page = 'friends'; // page is the ngModel name
constructor(
private router: Router
) { }
ngOnInit() {
}
selectFriends() {
this.router.navigateByUrl('/tabs/(activity:activity/(friends:friends)');
}
selectNearMe() {
this.router.navigateByUrl('/tabs/(activity:activity/(nearme:nearme)');
}
selectGlobal() {
this.router.navigateByUrl('/tabs/(activity:activity/(global:global)');
}
segmentChanged(ev: any) {
console.log('Segment changed', ev);
}
}
Again, my issue is the component on the page does not get replaced with the component that I am navigating to. I am using router-outlets to load the components on the page. When the page first loads the component loads fine, when I click on another button (e.g. Near Me) it will show the near me component, but when I click on Friends (after clicking on Near Me) it does not replace the near me component with the friends component.