要将首页的URL设置为http://localhost:4200/,需要进行以下步骤:
在Angular项目的根目录中,打开src/app/app-routing.module.ts文件。
确保已经导入了RouterModule和Routes:
import { RouterModule, Routes } from '@angular/router';
Routes数组中添加一个新的路由,将其path属性设置为空字符串,将其redirectTo属性设置为'home'(或者你想要的默认路由路径):const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
// 其他路由
];
RouterModule.forRoot(routes)添加到imports数组中:@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
打开src/app/app.component.html文件。
在标签之前添加一个新的路由链接,将其routerLink属性设置为空字符串:
现在,当你在浏览器中运行Angular应用时,首页的URL将会是http://localhost:4200/。