typescript - Cannot match any routes with child routes and new angular 2 RC1 router -
applicationcomponent
import { component } '@angular/core'; import {router, router_directives, routes, router_providers} '@angular/router'; import {schoolyearscomponent} "./schoolyear/schoolyears.component"; @component({ directives: [router_directives], providers: [ router_providers ], templateurl: './app/application.component.html', styleurls: ['./app/application.component.css'] }) @routes([ { path: '/', component: schoolyearscomponent, }, ]) export class applicationcomponent {}
schoolyearscomponent
import { component } '@angular/core'; import { routes, router_directives } '@angular/router'; import { schoolyearshomecomponent } './schoolyears.home.component'; import { createschoolyearcomponent } './create.schoolyear.component'; @routes([ { path: '', component: schoolyearshomecomponent, }, { path: '/create', component: createschoolyearcomponent } ]) @component({ template: `<router-outlet></router-outlet>`, directives: [router_directives]}) export class schoolyearscomponent { }
schoolyears.component.html
<h3>schoolyears</h3> <div> <a [routerlink]="['/create']">create</a> </div> <table> <tr *ngfor="let s of schoolyears" (click)="createschoolyear()"> <td>{{s.id}}</td> <td>{{s.name}}</td> <td>{{s.startdate}}</td> <td>{{s.enddate}}</td> </tr> </table>
when click on "create" routerlink error:
error
exception: error: uncaught (in promise): cannot match routes. current segment: 'create'. available routes: ['/'].
why child route not loaded? why /create route not in available array of routes?
update
this not relevant anymore in new v3-beta.2 router.
original
change
@routes([ {path: '', component: schoolyearshomecomponent}, {path: '/create', component: createschoolyearcomponent} ])
to
@routes([ {path: '/create', component: createschoolyearcomponent}, {path: '', component: schoolyearshomecomponent}, ])
the order of routes significant. specific routes should come first, least specific routes last. known issue , should fixed soon.