2017-07-20 30 views
1

我期待添加一個基地href到我的webapp。目前一切運行時正常運行:角1基地href和路由/意見/控制器

  • 本地主機:3000 /#/登錄

但我需要添加基本href或 「充電」 - >本地主機:3000 /充電/#/登錄

當前的index.html

<head> 
<base href="charge/" /> 
<meta charset="utf-8"> 
<meta name="description" content=""> 
<meta name="viewport" content="width=device-width"> 
<link rel="stylesheet" .... 
</head> 

Anuglar路由文件

function routerConfig($routeProvider, $locationProvider) { 
$routeProvider 
    .when('/map', { 
    templateUrl: 'app/views/main/main.html', 
    controller: 'MainController', 
    controllerAs: 'mainCtrl' 
    }) 
    .when('/login', { 
    templateUrl: 'app/views/login/login.html', 
    controller: 'LoginController', 
    controllerAs: 'loginCtrl' 
    }) 
    .when('/list', { 
    templateUrl: 'app/views/list/list.html', 
    controller: 'ListController', 
    controllerAs: 'listCtrl' 
    }) 
    .when('/reporting', { 
    templateUrl: 'app/views/reporting/reporting.html', 
    controller: 'ReportingController', 
    controllerAs: 'reportingCtrl' 
    }) 
    .otherwise({ 
    redirectTo: '/map' 
    }); 
// $locationProvider.html5Mode(true); 
} 

每當我跑我與basehref應用和導航爲localhost:3000 /充電/#/登錄,基本上每個視圖,控制器,涼亭組件和模塊無法找到。我嘗試編輯路由器,更改主應用程序文件夾的名稱,但無法使其工作。我知道我缺少一些小東西,所以任何幫助都非常感謝!

我的問題似乎與Base Href and Angular Routing and Views非常相似,但我真的不知道這一點。

回答

2

如果您使用Chrome和您在開發者控制檯看看,看看什麼對資源的URL無法找到:

http://localhost:8080/charge/app.js

它正在考慮的根項目,然後爲名爲charge的文件夾,然後爲資源。

HTML元素指定用於文檔中包含的所有相對 URL的基本URL。文檔中只能有一個元素 。 - MDN

你能告訴我們你的目錄結構是什麼樣子嗎?如果您的項目文件直接位於根目錄中,請嘗試製作一個名爲「charge」的子文件夾並將其中的所有文件放入其中。

例子:根>收費>項目文件

有用的鏈接:AngularJS: Changing App Path, and the Element

+0

簡單,但是這並獲得成功,謝謝! – reedb89

0

嘗試在所有源URL前加上「/」。這將開始每個路徑在你的項目的根目錄,而不是在你的基礎href。

例如templateUrl: '/app/views/main/main.html'