角度力是URL中不需要的感叹号 [英] Angular force an undesired exclamation mark in url

查看:156
本文介绍了角度力是URL中不需要的感叹号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击此内容时:< a href =#/ home>主页< / a> 网址为 localhost /网站/应用/#!/#%2Fhome



当我点击此内容时:< a href = #!/ home>主页< / a> 网址为 localhost / Sites / App /#!/ home



但这仅适用于我的电脑,对于我的同事而言则相反,如果有,则链接不起作用!在网址中。



我理解SEO最佳做法,但我们没有公共网站,我们需要在网址中没有感叹号的网站。



我理解url中的 / 是编码的,因为angular认为这不是路径分隔符,而是为什么在我唯一的计算机中?我们有相同的代码。



我们使用IIS或IIS express,Chrome或IE,没有任何区别。当它适用于我时,它不适用于所有其他。



在浏览器网络调用中,我们可以看到链接上的点击之间没有服务器调用这是模块配置:

  angular.module('paper.app',['ngMaterial'
,'ngMessages'
,'ngRoute'
,...])
.config(function( $ routeProvider,$ mdThemingProvider,$ mdIconProvider,$ locationProvider,$ mdDateLocaleProvider,contentUrl,contentSvg){

$ routeProvider
.when(/,{
templateUrl:contentUrl + 'view-home / html / home.html',
控制器:'HomeController',
控制器:'homeCtrl'
})
.otherwise({
redirectTo :'/'
});

$ locationProvider。 html5Mode(false);

...
});

这是bower.json:

  {
name:...,
version:1.0.0,
authors:[
...
],
忽略:[
node_modules,
bower_components
],
description :,
main:,
主页:,
依赖:{
angular:^ 1.5.7,
angular-material:^ 1.0.9,
angular-route:^ 1.5.7,
angular-material-data-table:^ 0.10.9,
时刻:^ 2.14.1
}
}


解决方案

我通过添加以下内容解决了这个问题:

  $ locationProvider.hashPrefix( ''); 


When I click on this : <a href="#/home">home</a> the url is localhost/Sites/App/#!/#%2Fhome

When I click on this : <a href="#!/home">home</a> the url is localhost/Sites/App/#!/home

But this only works on my computer, for my co-workers it's the opposite, the links don't works if there are ! in the url.

I understand the SEO best practices but we don't have a public website, we need to have a website working without exclamation mark in url.

I understand the / in the url are encoded because angular think this is not a path separator but why in my only computer ? We have the same code.

We use IIS or IIS express, Chrome or IE, there are no differences. When it works for me, it does not work for all of the others.

In the browser networks calls we can see there are no server calls between the click on the link and the bad url generation.

This is the module configuration :

angular.module('paper.app', [ 'ngMaterial'
                        , 'ngMessages'
                        , 'ngRoute'
                        , ...])
   .config(function ($routeProvider, $mdThemingProvider, $mdIconProvider, $locationProvider, $mdDateLocaleProvider, contentUrl, contentSvg) {

       $routeProvider
           .when("/", {
               templateUrl: contentUrl + 'view-home/html/home.html',
               controller: 'HomeController',
               controllerAs: 'homeCtrl'
           })
           .otherwise({
               redirectTo: '/'
           });

       $locationProvider.html5Mode(false);

       ...
   });

This is the bower.json :

{
    "name": "...",
    "version": "1.0.0",
    "authors": [
        "..."
    ],
    "ignore": [
        "node_modules",
        "bower_components"
    ],
    "description": "",
    "main": "",
    "homepage": "",
    "dependencies": {
        "angular": "^1.5.7",
        "angular-material": "^1.0.9",
        "angular-route": "^1.5.7",
        "angular-material-data-table": "^0.10.9",
        "moment": "^2.14.1"
      }
}

解决方案

I solved it by adding this:

$locationProvider.hashPrefix('');

这篇关于角度力是URL中不需要的感叹号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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