[英]AngularJS URL get escaped with $locationProvider.html5Mode(true)
[英]AngularJS $locationProvider.html5Mode(true) gives error `url is undefined`
我正在嘗試將html5Mode用於AngularJS中的網址。
這段代碼運行良好:
.config(["$routeProvider", "$locationProvider",
function($routeProvider, $locationProvider){
$routeProvider.when("/editor", {
templateUrl: "pages/editor/index.html"
})
.when("/docs", {
templateUrl: "pages/docs/index.html"
}).otherwise({
templateUrl: "pages/home/index.html"
});
}
]);
但是這段代碼給我錯誤的url is undefined
.config(["$routeProvider", "$locationProvider",
function($routeProvider, $locationProvider){
$routeProvider.when("/editor", {
templateUrl: "pages/editor/index.html"
})
.when("/docs", {
templateUrl: "pages/docs/index.html"
}).otherwise({
templateUrl: "pages/home/index.html"
});
$locationProvider.html5Mode(true);
}
]);
問題可能是我有而不是
這可能是什么原因?
我只是遇到了同樣的問題,並且想出了解決方法。 好吧,我的錯誤是:
我沒有注入“ $ locationProvider”,而在函數開始時沒有引用“ $ locationProvider”,而是試圖調用“ html5Mode”,現在我有了:
app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) { $routeProvider .when("/", { templateUrl: "Views/home/home.html", controller: "HomeController" }) .otherwise({ redirectTo: '/'}); $locationProvider.html5Mode(true);}]);
我輸入錯誤,輸入:“ href =” /“”
但我使用Wampp在本地服務器上運行所有應用程序,因此項目的基本路徑是“ / NAME_OF_THE_PROJECT /”,如下所示:
<base href="/SEQUOIA/">
通過這兩次更正,我解決了所有錯誤,如我所見,您的基准沒有最后一個'/',也許您的應用正在搜索“ www.localhost.com/staticCONTENT”而不是“ ... / static / CONTENT” 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.