1)创建新项目
ng new angular-test
ng g component projects
ng g component typings
Run Code Online (Sandbox Code Playgroud)
2)添加简单路由
/src/app/app.component.html
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)
/src/app/app.module.ts
export const ROUTES: Routes = [
{
path: '',
redirectTo: '/projects',
pathMatch: 'full'
},
{
path: 'projects',
component: ProjectsComponent,
},
{
path: '/typings',
component: TypingsComponent
},
{
path: '**', redirectTo: ''
}
];
@NgModule({
declarations: [
AppComponent,
ProjectsComponent,
TypingsComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forChild(ROUTES)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
EXCEPTION: …Run Code Online (Sandbox Code Playgroud) angular ×1