我已经使用Angular CLI构建了一个Angular2应用程序,其中包含许多路线。 该应用程序工作得很好。我可以使用链接导航到所有路线,使用URL或使用路由器的导航功能。我随时可以在任何路线上刷新浏览器页面。在部署中服务Angular2应用程序(由Angular CLI构建)
但是,当我试图从dist/index.html使用单独的Web服务器(在生产环境中,在dev或express/nginx/apache2上括号IDE服务器)服务我的应用程序时,应用程序路由行为是不同的。
应用程序流程正常工作,但是当涉及到直接点击URL(对于任何路线)或任何路线应用程序显示时刷新页面无法获取/仪表板错误。这里仪表板是我的路线名称。我在任何现有路由页面的刷新页面上遇到同样的错误。
我想应用程序只能从index.html引导,而不能从应用程序的任何地方引导。
我做错了,请帮忙。
的index.html
<script>
System.import('system-config.js').then(function() {
System.import('main');
}).catch(console.error.bind(console));
</script>
main.ts
自举(NgUnityAppComponent,[ HTTP_PROVIDERS, ROUTER_PROVIDERS ]);
NG-unity.component.ts文件
import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
import {APP_ROUTES} from './ng-unity.routes';
import { NavbarComponent, FooterComponent, AboutUsComponent } from './shared/index';
import {NavbarService} from './shared/navbar/navbar.service';
@RouteConfig(APP_ROUTES)
@Component({
moduleId: module.id,
selector: 'ng-unity-app',
templateUrl: 'ng-unity.component.html',
styleUrls: ['ng-unity.component.css'],
directives: [ROUTER_DIRECTIVES, NavbarComponent, FooterComponent],
providers:[NavbarService]
})
export class NgUnityAppComponent {
}
我做错了吗?请帮忙。
http://stackoverflow.com/questions/31415052/angular-2-0-router-not-working-on-reloading-the-browser这解释了原因和解决方案。 –