【发布时间】:2019-04-18 07:14:35
【问题描述】:
我使用侧面菜单模板创建了一个项目。
在侧面菜单中有两个方面(城市和天气)。
第三页显示来自 URL 的所选城市的天气)。
我有 3 条路线:
/cites -> 城市页面
/weather -> weather-overview.page
/weather/:id -> weather-detail.page
在两个天气页面上,我想显示一个包含所有选定城市的标签栏。
这个标签栏在一个自己的组件中(city-tab.component):
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button *ngFor="let city of cityList" [routerLink]="['/weather', city.ID]">
<ion-label>{{city.Name}}</ion-label>
<img src="https://www.countryflags.io/{{city.Country}}/shiny/16.png">
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
我的问题是,如果我想在底部显示这个组件,我无法点击当前页面的内容/weather和/weather/:id。
chrome-inspector 检测到<ion-router-outlet _ngcontent-eyp-c2 tabs="true" class="hydrated"></ion-router-outlet>
这阻止了空穴离子含量。
上面的一些行是第二个<ion-router-outlet main...。
但内容正在显示。
这里是 weather-overview.page.html
<ion-header>
<ion-toolbar color="primary">
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>Weather</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-button (click)="handleclick()">Click</ion-button>
<app-city-tabs></app-city-tabs>
</ion-content>
我还有 3 个模块: - 带有路由到其他模块的 AppModule - city.page 的 CityPageModule - 两个天气页面的 WeatherModule。
它们将通过延迟加载来加载。
我也尝试在 app.component 中集成<app-city-tabs>,但这没有帮助。
感谢您的帮助,不胜感激。
app.component.ts:
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
public appPages = [
{
title: 'Weather',
url: '/weather',
icon: 'sunny'
},
{
title: 'Cities',
url: '/cities',
icon: 'business'
}
];
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
}
app.component.html
<ion-app>
<ion-split-pane>
<ion-menu>
<ion-header>
<ion-toolbar color="primary">
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">
<ion-item [routerDirection]="'root'" [routerLink]="[p.url]">
<ion-icon slot="start" [name]="p.icon"></ion-icon>
<ion-label>
{{p.title}}
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet main></ion-router-outlet>
</ion-split-pane>
</ion-app>
city-tabs.component.ts
import { Component, OnInit } from '@angular/core';
import { CityLoaderService } from 'src/app/_sevices/city-loader.service';
import { City } from 'src/app/_models/city';
import { Router } from '@angular/router';
@Component({
selector: 'app-city-tabs',
templateUrl: './city-tabs.component.html',
styleUrls: ['./city-tabs.component.scss'],
})
export class CityTabsComponent implements OnInit {
cityList: City[];
constructor(private cityLoader: CityLoaderService) {
}
ngOnInit() {
this.cityList = this.cityLoader.getCities();
}
}
app-routing.module.ts
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', redirectTo: 'weather', pathMatch: 'full'},
{ path: 'cities', loadChildren: './cities/cities.module#CitiesPageModule' },
{ path: 'weather', loadChildren: './weather/weather.module#WeatherPageModule' }
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
【问题讨论】:
-
请您添加 app.component.ts 和 app.component.html 页面的代码。谢谢。
-
@LloydNicholson 两个文件都附上了。
-
我认为问题出在您的路由模块上。请分享 app-routing.module.ts。您设置的 weather/:id 路线可能是问题所在。
-
@LloydNicholson 我在上面附上了这两个文件。谢谢你的回答。
标签: angular ionic-framework ionic4