首页 > 解决方案 > 不同静态登录页面的角度设置基本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

解决方案


为了实现这一点,在 angular.json 文件下的 assets 部分中添加所有静态路径

"assets": [
"src/LandingPage1",
"src/LandingPage2",
"src/LandingPage3",
]

更改后再次运行 ng serve 命令,您将能够访问这些文件夹中的静态页面。

请点击链接获取完整指南:点击这里


推荐阅读