Background

Angular App是使用angular-cli@1.0.0-rc.0创建的.Angular App包含一个NavbarComponent,它显示两个菜单项“Home”和“About” . Angular App使用Angular Router和NavbarComponent来允许用户导航到两个组件视图:HomeComponent View和AboutComponent View . 应用程序的基本路由设置在index.html as中 . 定义路由器配置文件并定义两条路由,一条路由作为HomeComponent默认路由,路径为:'',一条路由为AboutComponent路径,路径为:'about' . 从app.routing.ts导出ConfiguredRouterModule将ConfiguredRouterModule导入app.module.ts . 指令在AppComponent HTML模板中定义 . 为NavbarComponent内的每个菜单项链接定义了routerLink指令 . 要构建项目,我使用angular-cli命令“ng build --prod” . 我将文件从“dist”文件夹复制到目标Web服务器文件夹 . 请注意,目标Web服务器文件夹是Web服务器上根文件夹下的子文件夹 . 示例“root / projects / router”而不仅仅是“root”文件夹

NavbarComponent Menu Item Links correctly render Component Views

当用户单击其中一个或NavbarComponent菜单项链接“Home”或“About”时,正确的Component View显示在AppComponent HTML模板内部

Issue

当用户手动将浏览器中的URL从“website / projects / router /”更改为“website / projects / router / about”而不是AboutComponent显示时,将显示404 Page Not Found Error

执行命令 ng build --prod 后,我必须将 <base href="value"><base href="/"> 更改为 <base href="/projects/router/"> .

请注意,如果我尝试使用angular-cli命令 ng build --prod --base-href projects/router 构建项目,执行命令后,如果我打开"dist"文件夹中的index.html文件,我看到angular-cli将 <base href="value"><base href="/" 更改为 <base href="C:/Program Files/Git/projects/router/>

My Questions

如何构建Angular项目以正确设置 <base href="value"> ?更重要的是,如果用户手动将浏览器中的URL更改为有效的路由器路径路径,为什么Angular App会出现404错误?示例"website/projects/router/about"