繁体   English   中英

离子/角度:错误:无法匹配任何路线。 URL段

[英]Ionic / Angular: Error: Cannot match any routes. URL Segment

当我想从列表中的组件打开详细视图时,出现此错误。 我正在使用Ionic 4。

错误错误:未捕获(承诺):错误:无法匹配任何路由。 网址段:“ 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>

app-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值吗?

我的解决方案:
一入列表页面
构造函数(专用路由器:路由器){}
b方法:this.router.navigateByUrl('/ algodetail /'+ paramValue);

2-详细页面
一个构造函数(专用路由器:ActivatedRoute){}
b获取值:this.router.snapshot.params.paramValue;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM