我正在使用带有路由的Angular 2,我有一条路线可以很好地工作而另一条路线没有。我不确定我在第二次做错了什么。如果我导航到/ event / 650它匹配事件/:id路由,但是如果我导航到/ event / 2017/04/04我得到“错误:无法匹配任何路由”。
app.routes.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { CalendarComponent } from './calendar/calendar.component';
import { EventComponent } from './event/event.component';
export const routes: Routes = [
{
path: 'calendar',
component: CalendarComponent
},
{
path: 'event/:year/:month/:day',
component: EventComponent
},
{
path: 'event/:id',
component: EventComponent
},
{
path: 'event',
component: EventComponent
},
{
path: '**',
redirectTo: '/calendar',
pathMatch: 'full'
},
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
event.component.ts的片段:
ngOnInit() {
console.log(this.route.params['value']['id']);
};
如果我转到/ event / 650,这将记录id,但如果我删除了['id']键名,则当我将年/月/日放入网址时,我仍然会收到路径未找到错误。
有什么想法吗?