import {provide} from 'angular2/core';从'angular2/router'导入{APP_BASE_HREF};引导程序(应用程序组件,[ROUTER_PROVIDERS,提供(APP_BASE_HREF,{useValue:'/'});]);
在您的引导程序中.
I'm getting an error when reloading some of the routes in my app. First load works fine http://localhost:8001, and all other routes work from there. But if I reload page on some other route I get an exception below...
For example:
http://localhost:8001 works
http://localhost:8001/application works
http://localhost:8001/application/ doesn't work
http://localhost:8001/application/add doesn't work
I did some debugging and it turns out errors are generated by TemplateNormalizer, more specifically by HtmlParser.parse() method. When I removed <meta> tags from <head> errors were gone. But nothing else was happening - app didn't show - only <div class="app-loader"> was rendered even though SystemJS loaded all the modules in the background...
I also noticed one of my services was returning weird results, turns out I used relative URL. This lead me to add <base href="/"> to the header and that fixed all the issues... I'm not sure why, but it seams provide(APP_BASE_HREF, { useValue: '/' }) from bootstrap.ts is ignored in some places...
Add the base element just after the <head> tag. If the app folder is the application root, as it is for our application, set the href value exactly as shown here.
<base href="/">
Alternatively add
import {provide} from 'angular2/core';
import {APP_BASE_HREF} from 'angular2/router';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue : '/' });
]);