在AngularJS 1.2启用HTML 5模式 [英] Enabling HTML 5 Mode in AngularJS 1.2

查看:98
本文介绍了在AngularJS 1.2启用HTML 5模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作需要使用HTML 5模式的应用程序。由于这样的事实,我迁移现有的网站使用AngularJS 1.2,我不能在我的网址#标签。目前,我有以下几点:

I'm working on an app that needs to use HTML 5 mode. Due to the fact that I am migrating an existing site to use AngularJS 1.2, I cannot have '#' tags in my URL. Currently, I have the following:

angular.module('myApp', ['ngRoute']).
  config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);

  $routeProvider
    .when("/home", {templateUrl:'home.html', controller:'homeController'})
    // other routes are defined here..
    .otherwise({redirectTo: '/home'});
  }]);

不幸的是,当我访问的http:// myServer上的/ home ',我的应用程序不会在启用HTML 5模式。我得到一个404。然而,当我访问的http:// myServer上/ 它的工作原理。当我有支持HTML5模式下它就像深层链接无法正常工作。如果我注释掉,上面写着$ locationProvider.html5mode(真);行了,该网站的功能。然而,再一次,我不能在我的网址哈希标签,由于我迁移的现有站点的事实。

Unfortunately, when I visit 'http://myServer/home', my app does not work when html 5 mode is enabled. I get a 404. However, when I visit http://myServer/ it works. Its like deep-linking doesn't work when I have html5 mode enabled. If I comment out the line that says "$locationProvider.html5mode(true);", the site functions. However, once again, I cannot have hash tags in my URL due to the fact I'm migrating an existing site.

我误解html5mode(真)是如何工作的?或者,我是不是做错了什么?

Am I misunderstanding how html5mode(true) works? Or, am I doing something wrong?

感谢您

推荐答案

如果你使用 html5mode 你需要做在服务器端的变化来回报您的入口点 index.html的(主应用页面)。那么棱角分明的应用程序将解析URL并加载所需的网页。

If you're using html5mode you need make changes on the server side to return your entry point index.html (main app page) on any URL request. Then angular app will parse URL and load needed page.

这篇关于在AngularJS 1.2启用HTML 5模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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