env。 Ubuntu 16.04 节点:v10.15.1 npm:6.4.1
我新创建的Web应用程序中有两个页面,而html则更少。没有ajax调用。
这是我的package.json
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"bootstrap": "^3.3.7",
"core-js": "^2.5.4",
"ngx-bootstrap": "^3.2.0",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.13.0",
"@angular/cli": "~7.3.1",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
}
}
在chrome调试中,我看不到任何延迟,所有负载都在2-3毫秒内。但实际上,刷新需要2-3至4秒。
这就是我定义路线的方式。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import {AppComponent} from './app.component';
import {RegisterForm1Component} from './components/register/register-form1.component';
import {MembershipComponent} from './domain/membership.component';
const routes: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: '', redirectTo: '/register', pathMatch: 'full' },
{ path: 'login', component: MembershipComponent },
{ path: 'register', component: RegisterForm1Component }
];
@NgModule({
declarations: [],
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {
}
有什么主意吗?
答案 0 :(得分:1)
我在您的配置中看不到任何错误。但是您可以提高应用程序的性能:
检查您始终使用Angular路由,而不是在每个新路由上完全重新加载您的应用程序。
Use `<a [routerLink]="[url]">` and `this.router.navigate([url]);`
您可以使用AOT编译来增加应用的脚本编写时间