继续上一章,我们用命令行 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
打开浏览器
版权声明:本文为qq_41603102原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。