Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 index.html 在 Angular 8 应用程序中动态定义“base href”?
之前我用过--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]}] })