Angular 1 个基本 href 和 routing/views/controllers
Angular 1 Base href and routing/views/controllers
我希望将基本 href 添加到我的网络应用程序。当前 运行 在 运行ning 时一切正常:
- localhost:3000/#/登录
但我需要添加基本 href 或 "charge" -> localhost:3000/charge/#/login
当前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/charge/#/login 时,基本上找不到每个视图、控制器、bower 组件和模块。我试过编辑路由器,更改主应用程序文件夹的名称,但无法正常工作。我知道我遗漏了一些小东西,所以非常感谢您的帮助!
我的问题似乎与 Base Href and Angular Routing and Views 非常相似,但老实说我就是想不通。
尝试在所有源 URL 前添加一个“/”。这将从项目的根目录而不是基本 href 开始每个路径。
例如templateUrl: '/app/views/main/main.html'
如果您正在使用 Chrome 并查看开发人员控制台,请查看 URL 找不到的资源:
http://localhost:8080/charge/app.js
它正在查看项目的根目录,然后查找名为 charge 的文件夹,然后查找资源。
The HTML element specifies the base URL to use for all relative
URLs contained within a document. There can be only one element
in a document. - MDN
你能告诉我们你的目录结构是什么样的吗?如果您的项目文件直接位于根目录中,请尝试创建一个名为 "charge" 的子文件夹并将所有文件放入其中。
示例: root > charge > project files
我希望将基本 href 添加到我的网络应用程序。当前 运行 在 运行ning 时一切正常:
- localhost:3000/#/登录
但我需要添加基本 href 或 "charge" -> localhost:3000/charge/#/login
当前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/charge/#/login 时,基本上找不到每个视图、控制器、bower 组件和模块。我试过编辑路由器,更改主应用程序文件夹的名称,但无法正常工作。我知道我遗漏了一些小东西,所以非常感谢您的帮助!
我的问题似乎与 Base Href and Angular Routing and Views 非常相似,但老实说我就是想不通。
尝试在所有源 URL 前添加一个“/”。这将从项目的根目录而不是基本 href 开始每个路径。
例如templateUrl: '/app/views/main/main.html'
如果您正在使用 Chrome 并查看开发人员控制台,请查看 URL 找不到的资源:
http://localhost:8080/charge/app.js
它正在查看项目的根目录,然后查找名为 charge 的文件夹,然后查找资源。
The HTML element specifies the base URL to use for all relative URLs contained within a document. There can be only one element in a document. - MDN
你能告诉我们你的目录结构是什么样的吗?如果您的项目文件直接位于根目录中,请尝试创建一个名为 "charge" 的子文件夹并将所有文件放入其中。
示例: root > charge > project files