angular9 - Ionic5 / Angular9:navController.navigateForward 不起作用(错误:无法匹配任何路由。)
问题描述
我是新手Ionic 5
并尝试使用Angular 9
延迟加载navController.navigateForward
,但它不起作用。
我不知道这是否与我设置路由器的方式有关,或者什么。而且我在任何地方都找不到有关 navigateForward 的官方信息。
当我单击“转到详细信息”(如下)时,出现错误Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'details/'
这是标签页:
tabs-routing.module.ts 路由器:
const routes: Routes = [
{
path: '',
component: TabsPage,
children: [
{
path: '',
redirectTo: 'films',
pathMatch: 'full'
},
{
path: 'films',
children: [
{
path: '',
loadChildren: () => import('../films/films.module').then(m => m.FilmsPageModule),
pathMatch: 'full'
}
]
},
{
path: 'people',
children: [
{
path: '',
loadChildren: () => import('../people/people.module').then(m => m.PeoplePageModule),
pathMatch: 'full'
}
]
},
{
path: 'planets',
children: [
{
path: '',
loadChildren: () => import('../planets/planets.module').then(m => m.PlanetsPageModule),
pathMatch: 'full'
}
]
}
]
}
];
电影.page.html:
<ion-header>
<ion-toolbar color="primary">
<ion-title>Films</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-button expand="full" (click)="openDetails()">Go to Details</ion-button>
<ion-button expand="full" (click)="goToPlanets()">Switch to Planets</ion-button>
</ion-content>
电影.page.ts:
import { Component, OnInit } from '@angular/core';
import { NavController, NavParams } from '@ionic/angular';
@Component({
selector: 'app-films',
templateUrl: './films.page.html',
styleUrls: ['./films.page.scss'],
providers: [NavController, NavParams]
})
export class FilmsPage implements OnInit {
constructor(public navCtrl: NavController, public navParams: NavParams) { }
ngOnInit() {
}
openDetails() {
// original code adapted to ionic 5
// this.navCtrl.push('FilmDetailsPage');
this.navCtrl.navigateForward('/details/'); // not working !!
}
goToPlanets() {
// original code adapted to ionic 5
// this.navCtrl.parent.select(2);
this.navCtrl.navigateRoot('/tabs/planets'); // working fine
}
}
电影-routing.module.ts 路由器:
const routes: Routes = [
{path: '', component: FilmsPage, children: [
// if I don't comment this, I get an error
// {path: '', redirectTo: 'details'},
{path:'details', children: [
{
path: '', loadChildren: ()=> import('../film-details/film-details.module').then(m => m.FilmDetailsPageModule), pathMatch: 'full'
}
]
}
]}
];
电影细节.page.html:
<ion-header>
<ion-toolbar>
<ion-title>filmDetails</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
</ion-content>
解决方案
我对详细信息页面做了同样的事情,但我们使用了变量 id。你的情况应该是这样的
const routes: Routes = [
{
path: '',
component: FilmsPage
},
{
path: 'details',
children: [
{
path: '',
loadChildren: () =>
import('../film-details/film-details.module')
.then(m => m.FilmDetailsPageModule),
pathMatch: 'full'
}]
}
];
为路由设置 id 而不是“详细信息”,以便您将来可以通过深度链接访问它。
const routes: Routes = [
{
path: '',
component: FilmsPage
},
{
path: ':filmsID',
children: [
{
path: '',
loadChildren: () =>
import('../film-details/film-details.module')
.then(m => m.FilmDetailsPageModule),
}]
}
];
推荐阅读
- python - 使用python中的csv文件从目录中删除文件
- node.js - node.js selenium chrome headless 一个实例启动多个“chrome”进程
- go - 添加到 CookieJar 会导致 cookie 数据被清除
- svelte - 如何在 Sapper 中加载全局(PostCSS)样式?
- sql - 更改sql系统端口后自动批处理文件备份不起作用
- elasticsearch - 如何使用“不”来过滤 Elastic Search 中的术语?
- javascript - 使用某些方法时变量会发生变化
- api - Salesforce 通过命名凭据连接到 JWT 服务 - JWT 令牌交换
- r - 如何在 R 中制作数据透视表
- javascript - 如何在没有 ID 的情况下将项目添加到无序列表?