angular - 如何从 index.html 在 Angular 8 应用程序中动态定义“base href”?
问题描述
如何从 index.html 在 Angular 8 应用程序中动态定义“base href”?
之前我用过--base-href
,现在不支持了。
解决方案
您可以通过脚本设置属性并在 NgModule 中获取来动态设置基本 href。
//index.html
<script>
window['base-url'] = window.location.pathname;
</script>
在您的模块中,您需要使用
@NgModule({
providers: [{provide: APP_BASE_HREF, useValue: window['base-url]}]
})
推荐阅读
- perl - perl/pdl 中的八度 fminunc 交替
- python-3.x - tkinter中的背景颜色不均匀
- tmux - 退格键在 tmux 命令提示符下不起作用
- sqlite - SQLite 索引在用于定位 NULL 时会降低性能
- mysql - 使用 MYSQL UNIQUE INDEX 和 INDEX
- swift - 为什么我得到一个线程 1:EXC_BAD_ACCESS(代码 = EXC_I386_GPFLT)
- c++ - 如何使用 std::distance 查找指向 std::array 元素的指针的数组索引?
- python - Python:为什么解释器在正在执行的行下方的函数中搜索变量赋值?
- java - 如何在线将数据存储为 HashMap?
- python - 使用 Haversine 包比较经度和纬度的 csv 列表的所有距离可能性