簡體   English   中英

如何修復我的角度4路由

[英]how to fix my angular 4 routing

我是Angular 4世界的新手,當我想路由到/ moviegroup /:id時遇到了此錯誤。 由於某種原因,我無法使其正常工作

app.routes.ts

import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
import { MovieComponent } from '.é/movie/movie.component';
import { WizardComponent } from './wizard/wizard.component';

const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'wizard', component: WizardComponent, pathMatch: 'full' },
    {
        path: 'moviegroup', 
        children: [
            { path: 'moviegroup/:id', component: MovieComponent, pathMatch: 'full' }
        ]
    }
];

export const routing = RouterModule.forRoot(routes, { preloadingStrategy: 
PreloadAllModules });

我可以導航到http:// localhost / wizardhttp:// localhost / moviegroup,但不能導航http:// localhost / moviegroup / ecf84479-c23c-1702-8440-b252591364ec 我收到以下錯誤:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'moviegroup/ecf84479-c23c-1702-8440-b252591364ec'
Error: Cannot match any routes. URL Segment: 'moviegroup/ecf84479-c23c-1702-8440-b252591364ec'

這是我的文件結構: 在此處輸入圖片說明

知道我做錯了什么嗎? 如果需要更多信息,請告訴我!

謝謝雷吉

從子路徑中刪除moviegroup

{
  path: 'moviegroup', 
  children: [
    { path: ':id', component: MovieComponent }
  ]
}

而且,除了在帶有redirectTo空路由路徑上之外,您無需在其他任何地方都包含pathMatch: 'full'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM