角力在 url 中产生一个不需要的感叹号 [英] Angular force an undesired exclamation mark in url

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

问题描述

当我点击这个:<a href="#/home">home</a> url 是 localhost/Sites/App/#!/#%2Fhome

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

当我点击这个:<a href="#!/home">home</a> url 是 localhost/Sites/App/#!/home

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.

我了解 SEO 最佳实践,但我们没有公共网站,我们需要一个网站在 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.

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

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.

我们使用 IIS 或 IIS express,Chrome 或 IE,没有区别.当它对我有用时,它不适用于所有其他人.

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.

在浏览器网络调用中,我们可以看到在点击链接和生成错误 url 之间没有服务器调用.

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

这是模块配置:

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);

       ...
   });

这是 bower.json :

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天全站免登陆