通过Ionic 4中的侧菜单路由页面


For days now I've been trying to route/link pages via the side-menu. So that I'm able to move to different pages from the side-menu itself. I've searched for tutorials on Angular 8 and Ionic 4 but couldn't find the specific article that relates to my issue.

我假设通过创建页面的组件(将在侧菜单上的项目(来路由页面,以便于路由。我也知道路由使用什么代码,但不知道在哪里使用,因为在错误的地方使用代码不会为我提供任何解决方案。

This is my app.component.ts file.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule, routeComponents } from './app-routing.module';
@NgModule({
declarations: [AppComponent, routeComponents],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}  

以下是app-routing.module.ts文件。

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { TrackComponent } from './track/track.component';
import { AboutComponent } from './about/about.component';
import { CategoryComponent } from './category/category.component';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadChildren: () => import('./home/home.component').then( m => 
m.HomeComponent)},
{ path: 'category', loadChildren: () => import('./category/category.component').then( m => 
m.CategoryComponent)},
{ path: 'track', loadChildren: () => import('./track/track.component').then( m => 
m.TrackComponent)},
{ path: 'about', loadChildren: () => import('./about/about.component').then( m => 
m.AboutComponent)}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routeComponents = [CategoryComponent, TrackComponent, AboutComponent, 
HomeComponent];

如果我还需要修改每个菜单项的html文件,请告诉我。如果可能的话,请试着用外行的术语向我解释

在ts文件中:

import { Router } from "@angular/router";
constructor(private router:Router){}
navtigateToPage(pageName){
this.router.navigate([pageName]);
}

在html文件中:

<ion-item (click)="navtigateToPage('track')">
<ion-label>track</ion-label>
</ion-item>

(点击(可以添加到任何节点元素(div、span、ion图标…(

相关内容

  • 没有找到相关文章

最新更新