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

时间:2018-11-29 01:31:08

标签: angular ionic-framework routing ionic4

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

  

错误错误:未捕获(承诺):错误:无法匹配任何路由。网址段:“ algodetail”

我发现了很多与此错误有关的主题,但没有找到解决方案。我不确定,也许只是拼写错误?

列表视图:

/usr/local/var/log/openvswitch/ovs-vswitchd.log

app-routing.module.ts中的路由:

<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>

algodetail.page.ts:

const routes: Routes = [
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'algodetail/:id', loadChildren: './algodetail/algodetail.module#AlgodetailPageModule' } 
];

algodetail.module.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() {

  }

}

我的文件系统

Filesystem

2 个答案:

答案 0 :(得分:1)

查看错误消息,似乎未设置ID。如果您在路由上启用enableTracing,它会为您提供更多信息吗?您可以确认确实为该路由设置了id值吗?

答案 1 :(得分:0)

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

2-详细页面
a-constructor(专用路由器:ActivatedRoute){}
b获取值:this.router.snapshot.params.paramValue;