PLS帮助错误错误:未捕获(承诺):错误:无法匹配任何路由。 URL段:'r2'错误:无法匹配任何路由。网址段:“ r2”

时间:2019-05-29 07:39:19

标签: javascript angular ionic-framework

请帮我解决问题。我不知道该怎么办,我的语法没有错,但是如果我运行它,则会显示错误

我的应用程序路由模块

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [

  { path: 'recipes',
  children: [
    {
      path: '',
      loadChildren:
      './recipes/recipes.module#RecipesPageModule'
    },
    {
      path: ':recipeId',
      loadChildren:
      './recipes/recipe-detail/recipe-detail.module#RecipeDetailPageModule'
    }
  ]},
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

我的食谱-service.ts

import { Injectable } from '@angular/core';
import { Recipe } from './recipe.model';

@Injectable({
  providedIn: 'root'
})
export class RecipesService {

  private recipes: Recipe[] = [
    {
      id: 'r1',
      title: 'Smoked Fish',
// tslint:disable-next-line: max-line-length
      imageUrl: '../assets/img/sugba.jpg',
      ingredients: ['Fish', 'Salt', 'Lemon Grass']
    },
    {
      id: 'r2',
      title: 'Raw Fish',
// tslint:disable-next-line: max-line-length
      imageUrl: '../assets/img/rawfish.jpg',
      ingredients: ['Fish', 'Salt', 'Onion']
    },
  ];

  constructor() { }
  getAllRecipes(){
    return [...this.recipes];
  }
  getRecipe(recipeId: string){
    return {...this.recipes.find(recipe => {
      return recipe.id === recipeId;
    })};
  }
}

我的食谱.page.html

<ion-header>
  <ion-toolbar>
    <ion-title color="primary">recipes</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
<ion-list>
  <ion-item *ngFor="let recipe of recipes" [routerLink]="['/', recipe.id]">
    <ion-avatar>
      <ion-img [src] = "recipe.imageUrl">

      </ion-img>
    </ion-avatar>
    <ion-label>
      {{recipe.title}}
    </ion-label>
  </ion-item>
</ion-list>
</ion-content>


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

0 个答案:

没有答案