Github 页面中的角度路由

时间:2021-03-08 01:47:34

标签: angular routes

我一直在尝试在 GithubPages 上部署一个小型 Angular 应用程序,但在使用相关链接时遇到了一些问题。

例如,有一个在新标签页中打开的链接,在本地完美运行。但在 github 页面上,它返回一个“error404”。

  <a href="\assets\pdfs\geography\unit_1\economias_regionales.pdf" target="_blank">
     <mat-icon aria-hidden="false" aria-label="pdf-icon">picture_as_pdf</mat-icon>Regional Economies
  </a>

我已经检查了 documentation ,并尝试制作镜像 404.html 但没有奏效。

我也尝试过 Deploy Angular 7 to github pages 中要求的解决方案,但也没有奏效,可能是我弄错了。

完整的项目是 here

有什么推荐吗? 感谢您的时间

1 个答案:

答案 0 :(得分:2)

从 href 中删除前导 /,因为这会修改链接的相关内容。

<a href="assets/pdfs/geography/unit_1/economias_regionales.pdf" target="_blank"></a>

This answer explains it fairly well.

  • 前导 / 的链接相对于网站的。在您的情况下,链接最终不正确:

    https://fabichazaa.github.io/assets/pdfs/geography/unit_1/economias_regionales.pdf
    
  • 不带前导 / 的链接与您应用的 <base href=""> 标签相关。在您的情况下,链接最终是正确的:

    https://fabichazaa.github.io/schoolsystem/assets/pdfs/geography/unit_1/economias_regionales.pdf
    

您会看到它在本地运行,因为在这种情况下,应用程序恰好在网站的根目录下提供服务。

相关问题