小编Jam*_*mes的帖子

在部署时运行 ng build 后,角度路由不起作用

不知道我在这里做错了什么,我对 Angular 相当陌生,并且在路由方面有些摸索。

我正在运行 Angular 12.2.0 并在本地主机上设置了路由。我现在只是在两个页面之间导航,看看它是如何工作的,它在本地工作得很好。

例如,在 localhost 上,我可以从根 http://localhost:4200/ 浏览到 http://localhost:4200/locations,效果很好。

 const routes: Routes = [
  {path: '', component: HomeComponent},
  {path: 'locations', component: LocationsComponent}
];
Run Code Online (Sandbox Code Playgroud)

当我运行ng build构建项目时,它运行良好,我可以正常打开index.html

我不能做的是不再在路线之间导航

dist/angular-app/index.html当我单击要链接到的位置链接时启动构建,该dist/angular-app/index.html/locations链接是空白的,即使我将 URL 更改为dist/angular-app/locations也是空白的

有人指出我为什么这样做的正确方向吗?

非常感谢

附上我的 angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": { …
Run Code Online (Sandbox Code Playgroud)

routes build angular ng-build

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

build ×1

ng-build ×1

routes ×1