有额外的 Angular 网络应用程序!在网址中 [英] Angular web app having extra ! in the url

查看:23
本文介绍了有额外的 Angular 网络应用程序!在网址中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 ec2 ubuntu 16.04 上运行的基本 Angular webapp,使用路由($routeProvider).当我打开应用程序主页时说 example.com,而不是打开 http://example.com/#/ 它打开 http://example.com/#!/ 还有一个额外的!这弄乱了整个 url/路由结构.不知道我做错了什么,请指教.

I have a basic Angular webapp running on ec2 ubuntu 16.04, using routing($routeProvider). When I open the application home page say example.com, instead of opening http://example.com/#/ it opens http://example.com/#!/ there is an extra ! which is messing up the whole url/routing structure. Not sure what I am doing wrong, Please advice.

推荐答案

Angular 1.6 版增加了!"到 $location.. 检查下面的角度页面...

Angular version 1.6 adds a "!" to $location.. check the angular page below...

https://docs.angularjs.org/guide/migration#commit-aa077e8

$location:

由于 aa077e8,用于 $location hash-bang 的哈希前缀URLs 已从空字符串 ('') 更改为 bang ('!').如果你的应用程序不使用 HTML5 模式或在浏览器上运行不支持 HTML5 模式,并且您没有指定自己的hash-prefix 那么客户端 URL 现在将包含一个 !字首.为了例如,URL 将变为而不是 mydomain.com/#/a/b/cmydomain.com/#!/a/b/c.

Due to aa077e8, the default hash-prefix used for $location hash-bang URLs has changed from the empty string ('') to the bang ('!'). If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a ! prefix. For example, rather than mydomain.com/#/a/b/c the URL will become mydomain.com/#!/a/b/c.

如果你真的不想有哈希前缀,那么你可以恢复通过向您的应用程序添加配置块的先前行为:

If you actually want to have no hash-prefix, then you can restore the previous behavior by adding a configuration block to you application:

appModule.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

这篇关于有额外的 Angular 网络应用程序!在网址中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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