ApplicationComponentnon può corrispondere eventuali itinerari con percorsi per bambini e nuovo router 2 RC1 angolare
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>
quando clicco su "Crea" routerLink ottengo questo errore:
errore
EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'create'. Available routes: ['/'].
Perché il percorso bambino non caricato? Perché la rotta/create non si trova nella matrice di percorsi disponibile?
Questo non ha aiutato. Ottengo lo stesso messaggio di errore. L'attuale segemnt "crea" non si trova nelle rotte disponibili. Sembravi conoscere il mio obiettivo, ma per essere sicuro: voglio sostituire schoolyears.component.html con create.schoolyear.component.html andando a "creare" l'url. – Pascal
Sembra funzionare bene in https://plnkr.co/edit/oksKwNmGvubDlpV45yEB?p=preview.Puoi provare a riprodurre il tuo problema con questo Plunker? –
Spero di aver aggiunto il routerLink (che hai dimenticato nell'esempio) nel posto giusto: https://plnkr.co/edit/vjCbsqZazr0rp77xjnSm?p=preview NULLA accade nel momento in cui lo fai clic? Possiamo procedere per favore con il mio link? – Pascal