【发布时间】:2022-12-17 17:08:20
【问题描述】:
不确定我在这里做错了什么,我对 Angular 还很陌生,并且在路由方面有些摸索。
我正在运行 Angular 12.2.0 并在本地主机上设置了路由。我现在只是在两个页面之间导航,看看它是如何工作的,它在本地工作正常。
例如,在 localhost 上,我可以从根目录 http://localhost:4200/ 浏览到 http://localhost:4200/locations ,效果很好。
const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'locations', component: LocationsComponent}
];
当我运行 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": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angular-app:build:production"
},
"development": {
"browserTarget": "angular-app:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
}
}
}
},
"defaultProject": "angular-app"
}
【问题讨论】:
标签: angular build routes ng-build