APP_BASE_HREF
预定义的 DI 令牌,用于和 PathLocationStrategy
一起使用的 base href。base href 是在生成和识别 URL 时应保留的 URL 前缀。
A predefined DI token for the base href to be used with the PathLocationStrategy
. The base href is the URL prefix that should be preserved when generating and recognizing URLs.
const APP_BASE_HREF: InjectionToken<string>;
使用说明
以下示例演示了如何使用此令牌为基本应用注入器配置 base href 值,以便 DI 框架可以在应用中的任何位置提供依赖项。
The following example shows how to use this token to configure the root app injector with a base href value, so that the DI framework can supply the dependency anywhere in the app.
import {Component, NgModule} from '@angular/core';
import {APP_BASE_HREF} from '@angular/common';
@NgModule({
providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
})
class AppModule {}