AngularJS $ locationProvider.html5Mode(真)基地址问题 [英] AngularJS $locationProvider.html5Mode(true) Base Url issue

查看:135
本文介绍了AngularJS $ locationProvider.html5Mode(真)基地址问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的基本网址的http://本地主机/ ABC / ,当我定义的角路由,角删除 / ABC 和重定向页面,以 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆