ApplicationComponent
import { Component } from '@angular/core'; import {Router, ROUTER_DIRECTIVES, Routes, ROUTER_PROVIDERS} from '@angular/router'; import {SchoolyearsComponent} from "./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 } from '@angular/core'; import { Routes, ROUTER_DIRECTIVES } from '@angular/router'; import { SchoolyearsHomeComponent } from './schoolyears.home.component'; import { CreateSchoolyearComponent } from './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 I click on "Create" routerLink, I get this error:
Mistake
EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'create'. Available routes: ['/'].
Why is the child route not loaded? Why is the / create route not in an accessible array of routes?
angular typescript angular2-routing
Pascal
source share