【问题标题】:how to fix my angular 4 routing如何修复我的 Angular 4 路由
【发布时间】:2017-12-10 21:51:41
【问题描述】:

我是 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'

这是我的文件结构:

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

谢谢,雷吉

【问题讨论】:

  • 尝试删除 pathMatch - 没有它我可以做你正在做的事情。我无法很好地解释它在任何地方的作用。

标签: javascript angular routing angular4-router


【解决方案1】:

从子路径中移除moviegroup

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

而且你不需要在任何地方包含pathMatch: 'full',除了redirectTo的空路径路径。

【讨论】:

    猜你喜欢
    • 2012-06-16
    • 2018-01-13
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    相关资源
    最近更新 更多