だから私は、角2について学ぶためのアプリを構築し、ターミナルでこの問題に遭遇してきた:角度2エラー:「/詳細/:ID」既存のルート「/詳細/:ID」とのコンフリクト
app/teacher-detail.component.ts(17,3): error TS2369: A parameter property is only allowed in a constructor implementation.
[0] app/teacher-detail.component.ts(18,3): error TS2369: A parameter property is only allowed in a constructor implementation.
[0] app/teacher-detail.component.ts(23,19): error TS2339: Property '_routeParams' does not exist on type 'TeacherDetailComponent'.
[0] app/teacher-detail.component.ts(24,8): error TS2339: Property '_teacherService' does not exist on type 'TeacherDetailComponent'.
今、私は問題を見つけることができないようです。私の他のリスト(student-detail.component.ts)はこのリストとほぼ同じようにフォーマットされていますが、エラーは表示されません。
私は考えさせEXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error during instantiation of Router! (RouterLink -> Router).
ORIGINAL EXCEPTION: Configuration '/detail/:id' conflicts with existing route '/detail/:id'
ORIGINAL STACKTRACE:
Error: Configuration '/detail/:id' conflicts with existing route '/detail/:id'
は、@RouteConfigで私のアプリのファイルである:
import {Component, Input, OnInit} from 'angular2/core';
import { RouteParams } from 'angular2/router';
import {Teacher} from './teacher';
import { TeacherService } from './teacher.service';
@Component({
selector: 'my-teacher-detail',
templateUrl:'app/teacher-detail.component.html',
})
export class TeacherDetailComponent implements OnInit {
@Input() teacher: Teacher;
contructor(
private _teacherService: TeacherService,
private _routeParams: RouteParams) {
}
ngOnInit() {
let id = +this._routeParams.get('id');
this._teacherService.getTeacher(id)
.then(teacher => this.teacher = teacher);
}
goBack() {
window.history.back();
}
}
クローム開発ツールに見て、私はこれを参照してください?
@RouteConfig([
{
path: '/dashboard',
name: 'Dashboard',
component: DashboardComponent,
useAsDefault: true
},
{
path: '/detail/:id',
name: 'TeacherDetail',
component: TeacherDetailComponent
},
{
path: '/detail/:id',
name: 'StudentDetail',
component: StudentDetailComponent
},
{
path: '/teachers',
name: 'Teachers',
component: TeachersComponent
},
{
path: '/students',
name: 'Students',
component: StudentsComponent
},
])
私は完全に固まっており、問題が何であるか把握できません。私はそれが/ detail/idのことと関係があると思われますが、そのうちの1つを削除しても全体的に問題が解決されないので、どのように進むべきかはわかりません。
ご協力いただきありがとうございます。
まあ、少なくとも1つのマッピングを削除する必要があります。つまり、全く同じURLで2つの異なるルートを設定することはできません。あなたがそれをすると、どうして正確に起こりますか? –
これで、/ detail/idをStudentDetailの名前で削除しました。私はダッシュボードから教師までナビゲートすることができますが、スチューデントリンクにナビゲートすると何も戻ってこないのです。 教師用のバージョンを削除した場合、生徒のリンクをクリックしても何も表示されません(別のエラーでも後でチェックします) しかし、私はまだTerminalに表示されているのと同じエラーに遭遇しています。 – Nathan
Typo: 'contructor'は' constructor'でなければなりません。タイプミスとして閉じる投票 –