Я занимаюсь базовым студенческим приложением, где у меня проблема с пониманием маршрутизации.routing in angular2 typescript (RC5)
app.modules.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
//import { HttpModule, JsonpModule, XHRBackend } from '@angular/http';
//import { InMemoryBackendService } from 'angular2-in-memory-web-api';
import { AppComponent } from './app.component';
import { routes } from './app.routes';
import { StudentsComponent } from './students.component';
//import { AddStudentComponent } from './add-student.component';
//import { StudentDetailComponent } from './student-detail.component';
import { StudentService } from './student.service';
@NgModule({
imports: [
BrowserModule,
FormsModule,
routes,
// HttpModule,
// JsonpModule
],
declarations: [
AppComponent,
StudentsComponent,
// AddStudentComponent,
// StudentDetailComponent
],
providers: [
StudentService,
// { provide: XHRBackend, useClass: InMemoryBackendService },
],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
app.routes.ts:
import { Routes, RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
//import { AddStudentComponent } from './add-student.component';
import { StudentsComponent } from './students.component';
//import { StudentDetailComponent } from './student-detail.component';
const appRoutes: Routes = [
{
path: '',
redirectTo: '/students',
pathMatch: 'full'
},
{
path: 'students',
component: StudentsComponent
}
// {
// path: 'add',
// component: AddStudentComponent
// },
// {
// path: 'update/:roll',
// component: StudentDetailComponent
// },
];
export const routes: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Я не понимаю, что плохого в маршрутизации, он не работает. Я пытаюсь отобразить компонент студентов как страницу по умолчанию.
Что означает «это не работает»? –
Какой сервер вы используете? У вас есть ' ' как первый ребенок в тэге '
'? –Эта строка дается после заголовка. – Hema