簡體   English   中英

AngularJS $ locationProvider.html5Mode(true)給出錯誤“ URL未定義”

[英]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);
    }
]);

問題可能是我有而不是

這可能是什么原因?

我只是遇到了同樣的問題,並且想出了解決方法。 好吧,我的錯誤是:

  1. 我沒有注入“ $ locationProvider”,而在函數開始時沒有引用“ $ locationProvider”,而是試圖調用“ html5Mode”,現在我有了:

     app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) { $routeProvider .when("/", { templateUrl: "Views/home/home.html", controller: "HomeController" }) .otherwise({ redirectTo: '/'}); $locationProvider.html5Mode(true);}]); 
  2. 我輸入錯誤,輸入:“ href =” /“”

但我使用Wampp在本地服務器上運行所有應用程序,因此項目的基本路徑是“ / NAME_OF_THE_PROJECT /”,如下所示:

<base href="/SEQUOIA/">

通過這兩次更正,我解決了所有錯誤,如我所見,您的基准沒有最后一個'/',也許您的應用正在搜索“ www.localhost.com/staticCONTENT”而不是“ ... / static / CONTENT” 。

啊! 我幾乎忘記了,我的.htaccess文件與此處此處顯示的相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM