https://angular.io/docs/ts/latest/guide/router.html
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.
The <base href="/">
tells the Angular router what is the static part of the URL. The router then only modifies the remaining part of the URL.
<head>
<base href="/">
...
</head>
Alternatively add
>= Angular2 RC.6
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
declarations: [AppComponent],
imports: [routing /* or RouterModule */],
providers: [{provide: APP_BASE_HREF, useValue : '/' }]
]);
in your bootstrap.
In older versions the imports had to be like
< Angular2 RC.6
import {APP_BASE_HREF} from '@angular/common';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
{provide: APP_BASE_HREF, useValue : '/' });
]);
< RC.0
import {provide} from 'angular2/core';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue : '/' });
]);
< beta.17
import {APP_BASE_HREF} from 'angular2/router';
>= beta.17
import {APP_BASE_HREF} from 'angular2/platform/common';
See also Location and HashLocationStrategy stopped working in beta.16
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…