gpt4 book ai didi

AngularJS 和 GitHub Pages - 加载模板问题

转载 作者:行者123 更新时间:2023-12-02 09:13:41 27 4
gpt4 key购买 nike

我正在尝试设置my Angular app在 GitHub 页面上 http://moroshko.github.io/seekdeck .

Angular 路由在 application.js 中定义:

<html ng-app="SeekDeck">
<head>
...
<script src="scripts/application.js"></script>
...
</head>
<body>
<div ng-view></div>
</body>
</html>

application.js 按预期从 /seekdeck/scripts 加载。

我的应用程序路线如下所示:

// Part of application.js
$routeProvider
.when("/", {
templateUrl: "templates/dashboard/dashboard.html",
...
})
...

当 Angular 尝试获取 dashboard.html 模板时,它会尝试从 /templates/dashboard 加载它,而不是 /seekdeck/templates/dashboard,因此找不到它。

知道为什么会发生这种情况,或者我该如何解决这个问题?

最佳答案

发生这种情况是因为 Angular 期望 url 相对于域的根目录,而不是相对于应用程序的位置。换句话说,它期望它与 moroshko.github.io 相关。不是moroshko.github.io/seekdeck .

您可以通过添加 base 轻松解决此问题元素到您的 html 页面,并设置其 href属性到您希望应用程序根目录所在的路径(在您的情况下 /seekdeck/ )

将以下标签放入 <head> 内您的 html 页面:

<base href="/seekdeck/" />

还要确保您设置 html5mode(true)$locationProvider .

有一篇关于它的优秀博客文章 HERE

关于AngularJS 和 GitHub Pages - 加载模板问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23330662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com