0

我是 Angular 4 世界的新手,当我想路由到 /moviegroup/:id 时遇到了这个错误。出于某种原因,我无法让它工作

应用程序.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'

这是我的文件结构: 在此处输入图像描述

知道我做错了什么吗?如果需要更多信息,请告诉我!

谢谢, 雷吉

4

1 回答 1

1

moviegroup从子路径中删除:

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

而且你不需要pathMatch: 'full'在空路径路径上包含任何地方redirectTo

于 2017-07-06T18:55:11.263 回答