继续上一章,我们用命令行 ng generate component login 生成了一个新的组件。现在我想让它成为一个新的页面,不仅仅让他成为其他页面的组件。

1、修改app.component.html

<router-outlet></router-outlet>

 

2、修改路由app-routing.module.ts

import { NgModule } from '@angular/core';
import { LoginComponent } from './login/login.component';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: '',   redirectTo: '/login', pathMatch: 'full' },
  { path: 'login', component: LoginComponent },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

3、测试

ng serve --port 4300

打开浏览器

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐