AngularJS $ locationProvider.html5Mode(真)基地址问题 [英] AngularJS $locationProvider.html5Mode(true) Base Url issue
问题描述
我的应用程序的基本网址的http://本地主机/ ABC /
,当我定义的角路由,角删除 / ABC $ C $从基础URL C>和重定向页面,以
HTTP://localhost/index.html
。网址应为 HTTP://localhost/abc/index.html
。
My application base url is http://localhost/abc/
, when I define the angular routing, the angular removes the /abc
from the base url and redirect the page to http://localhost/index.html
. The Url should be http://localhost/abc/index.html
.
请参阅以下code为角路由:
See the following code for angular routing:
var routeConfig = function ($routeProvider, $locationProvider) {
$routeProvider.
when('/',{
templateUrl: "index.html", // URL : http://localhost/abc/index.html
}).
when('/about',{
templateUrl: "about.html", // URL : http://localhost/abc/about.html
}).
when('/contact',{
templateUrl: "contact.html", // URL : http://localhost/abc/contact.html
}).
otherwise({
redirectTo: "/"
});
$locationProvider.html5Mode(true);
}
routeConfig.$inject = ['$routeProvider', '$locationProvider'];
请帮助解决这个问题。
推荐答案
这是正常的。您需要添加<基本href =/ ABC/>
在< HEAD>
标记。当您使用html5Mode它会使用这个标签来设置基本URL。
That's normal. You need to add <base href="/abc" />
in your <head>
tag. When you use html5Mode it will use this tag to set the base url.
这篇关于AngularJS $ locationProvider.html5Mode(真)基地址问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!