Ionic / Angular: Error: Cannot match any routes. URL Segment
Ionic / Angular: Error: Cannot match any routes. URL Segment
当我想从我的列表中的组件打开详细视图时出现此错误。我正在使用 Ionic 4。
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'algodetail'
我找到了很多有此错误的主题,但没有找到解决方案。我不确定,也许只是拼写错误?
列表视图:
<ion-content padding>
<ion-card *ngFor="let algo of algoList | async" routerLink="/algodetail/{{algo.id}}">
<ion-card-header>
{{ algo.title }}
</ion-card-header>
</ion-card>
</ion-content>
应用程序中的路由-routing.module.ts:
const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'algodetail/:id', loadChildren: './algodetail/algodetail.module#AlgodetailPageModule' }
];
algodetail.page.ts:
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Algo } from '../models/algo';
import { FirestoreService } from '../services/data/firestore.service';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-algodetail',
templateUrl: './algodetail.page.html',
styleUrls: ['./algodetail.page.scss'],
})
export class AlgodetailPage implements OnInit {
public algo: Observable<Algo>
constructor(private firestoreService: FirestoreService, private route: ActivatedRoute ) {
}
ngOnInit() {
}
}
algodetail.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { AlgodetailPage } from './algodetail.page';
const routes: Routes = [
{
path: '',
component: AlgodetailPage
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [AlgodetailPage]
})
export class AlgodetailPageModule {}
我的文件系统
查看报错信息,好像是id没有设置。如果您在路线上打开 enableTracing,它会为您提供更多信息吗?您能否确认确实为路线设置了 id 值?
我的解决方案:
1-在列表页面
a-constructor(私有路由器:路由器){}
b-方法:this.router.navigateByUrl('/algodetail/' + paramValue);
2-详细页面
a-constructor(专用路由器:ActivatedRoute){}
b-获取值:this.router.snapshot.params.paramValue;
当我想从我的列表中的组件打开详细视图时出现此错误。我正在使用 Ionic 4。
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'algodetail'
我找到了很多有此错误的主题,但没有找到解决方案。我不确定,也许只是拼写错误?
列表视图:
<ion-content padding>
<ion-card *ngFor="let algo of algoList | async" routerLink="/algodetail/{{algo.id}}">
<ion-card-header>
{{ algo.title }}
</ion-card-header>
</ion-card>
</ion-content>
应用程序中的路由-routing.module.ts:
const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'algodetail/:id', loadChildren: './algodetail/algodetail.module#AlgodetailPageModule' }
];
algodetail.page.ts:
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Algo } from '../models/algo';
import { FirestoreService } from '../services/data/firestore.service';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-algodetail',
templateUrl: './algodetail.page.html',
styleUrls: ['./algodetail.page.scss'],
})
export class AlgodetailPage implements OnInit {
public algo: Observable<Algo>
constructor(private firestoreService: FirestoreService, private route: ActivatedRoute ) {
}
ngOnInit() {
}
}
algodetail.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { AlgodetailPage } from './algodetail.page';
const routes: Routes = [
{
path: '',
component: AlgodetailPage
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [AlgodetailPage]
})
export class AlgodetailPageModule {}
我的文件系统
查看报错信息,好像是id没有设置。如果您在路线上打开 enableTracing,它会为您提供更多信息吗?您能否确认确实为路线设置了 id 值?
我的解决方案:
1-在列表页面
a-constructor(私有路由器:路由器){}
b-方法:this.router.navigateByUrl('/algodetail/' + paramValue);
2-详细页面
a-constructor(专用路由器:ActivatedRoute){}
b-获取值:this.router.snapshot.params.paramValue;