angular - 不同静态登录页面的角度设置基本href
问题描述
我的文件夹结构:
/LandingPage1/
css/
images/
page1.html
page2.html
index.html
/LandingPage2/
css/
images/
page1.html
page2.html
index.html
/LandingPage3/
css/
images/
page1.html
page2.html
index.html
index.html
在 /index.html 中我添加了:
<base href="/">
<script>
(function() {
window['_app_base'] = '/' + window.location.pathname.split('/')[1];
})();
</script>
<body>
<app-root></app-root>
</body>
同样在 angular.json 中, index.html 的位置也发生了变化。
在 app.module 中:
providers: [
{ provide: APP_BASE_HREF, useValue: window['_app_base'] || '/' },
]
我想:
当我在浏览器中打开时localhost:4200/LandingPage1
<- 我将访问那些 page1、page2 等。
当我更改为localhost:4200/LandingPage2
-> 我将可以打开 /LandingPage2/page1.html
解决方案
为了实现这一点,在 angular.json 文件下的 assets 部分中添加所有静态路径
"assets": [
"src/LandingPage1",
"src/LandingPage2",
"src/LandingPage3",
]
更改后再次运行 ng serve 命令,您将能够访问这些文件夹中的静态页面。
请点击链接获取完整指南:点击这里
推荐阅读
- c++ - 由于 install(EXPORT "foo-targets" ...) 在导出集中多次包含目标 "foo",aws-cpp-sdk 在 Windows 构建期间失败
- file - 在 IntelliJ IDEA 中创建一个文件时生成多个文件
- laravel - 验证失败时,使用 URL 中的哈希重定向回来
- html - 为什么链接不能点击不是 100% 不透明度的图像
- c# - 如何在 Entity Framework Core 中模拟 SQL 触发器(代码优先)?
- r - 使用“ci”函数计算置信区间
- javascript - 如何在 react-leaflet 中使用 Leaflet 的 FeatureGroup 和 OverlappingMarkerSpiderfier?
- python - A python HTTP server does not accept connections
- javascript - How to show simple json file data on html Page?
- ios - 将“prefersLargeTitle”设置为 true 的 UINavigationController 不会立即显示大标题 - 您必须向上滚动才能显示