参考:https://angular.io/docs/ts/latest/guide/router.html
我的应用程序构建并加载正常。当我在任何浏览器中点击F5时,应用程序挂起:它在浏览器中显示“正在加载...”,控制台中不会显示任何错误消息。
通过消除,我发现app.html中的路由器插座似乎会导致问题。当我注释掉路由器插座时,应用程序正确重新加载。请注意,删除main.ts中的LocationStrategy无效。 我错过了什么?
main.ts
import { provide } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { AppComponent } from './app.component';
import { APP_ROUTER_PROVIDERS } from './app.routes';
bootstrap(AppComponent, [APP_ROUTER_PROVIDERS, provide(LocationStrategy, { useClass: HashLocationStrategy })]);
app.component.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
selector: 'my-app',
templateUrl: './app/app.html',
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent {
}
app.html
<!--<router-outlet></router-outlet>-->
<h1>this is app.html</h1>
的package.json
{
"version": "1.0.0",
"name": "samsblog",
"private": true,
"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start",
"build": "webpack --progress --profile --bail --display-error-details --minimize",
"postinstall": "typings install"
},
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "^3.0.0-beta.1",
"@angular/upgrade": "2.0.0-rc.4",
"bootstrap": "^3.3.6",
"core-js": "^2.4.0",
"es6-shim": "^0.35.0",
"html-webpack-plugin": "^2.22.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"ts-loader": "^0.8.2",
"zone.js": "^0.6.12"
},
"devDependencies": {
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"image-webpack-loader": "^2.0.0",
"source-map-loader": "^0.1.5",
"style-loader": "^0.13.1",
"typescript": "^1.8.10",
"typings": "^1.0.4",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^0.14.0"
}
}