角度网址添加了不需要的字符 [英] angular url is adding unwanted characters

查看:61
本文介绍了角度网址添加了不需要的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,通过访问

I had a project where the URL just worked fine when working locally by going to

localhost:9000/

localhost:9000/

URL将变为

http://localhost:9000/#/

作为我进行的一些更改,现在转到

As of some change I made it now goes to

http://localhost:9000/#!/(带有感叹号)

http://localhost:9000/#!/ ( with an exclamation mark )

此外,其他URL也变得很奇怪.如果我尝试单击一个链接,例如,转到仪表板.它不带我去那里.相反,它使URL类似于

Also, other URLs become weird. if I try to click on a link that for example, goes to the dashboard. It doesn't take me there. Instead, it makes the URL like

/#!/#%2Fdashboard

/#!/#%2Fdashboard

,此后什么也没有发生.我做错了什么,我该如何解决?我不显示任何代码,因为我不知道哪里出错了.我按照下面的教程进行操作,然后就出现了问题.也许错误在那里?

and nothing happens after that. What did I do wrong and how can I possibly solve this? I can't show any code since I don't know where I went wrong. I followed the following tutorial and after that, the problem occurred. Perhaps the mistake is there?

教程链接

我在设置路由的地方添加了.config.

I added my .config where I set up the routes.

  .config(function ($routeProvider, $httpProvider) {
$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'MainCtrl',
    controllerAs: 'vm',
    activetab: 'main'
  })
  .when('/about', {
    templateUrl: 'views/about.html',
    controller: 'AboutCtrl',
    controllerAs: 'vm',
    activetab: 'about'
  })
  .when('/faq', {
    templateUrl: 'views/faq.html',
    controller: 'FaqCtrl',
    controllerAs: 'vm',
    activetab: 'faq'
  })
  .when('/dashboard', {
    templateUrl: 'views/dashboard.html',
    controller: 'DashboardCtrl',
    controllerAs: 'vm',
    activetab: 'dashboard'
  })
  .when('/logout', {
    templateUrl: 'views/main.html',
    controller: 'LogoutCtrl',
    controllerAs: 'vm'
  })
  .otherwise({
    redirectTo: '/'
  });
  $httpProvider.interceptors.push(['$q', '$window', '$localStorage', function($q, $window, $localStorage) {
    return {
      'request': function (config) {
        config.headers = config.headers || {};
        if ($localStorage.globals) {
          config.headers.access_token = $localStorage.globals.currentUser.token;
        }
        return config;
      },
      'responseError': function(response) {
        switch(response.status) {
          case 403:
            //$window.location = '/'
            break;
          case 404:
            //$window.location = './404.html';
            break;
          case 500:
            $window.location = './500.html';
            break;
        }
        return $q.reject(response);
      }
    };
  }]);

推荐答案

这实际上不是错误.

请参见 commit-aa077e8

用于$ location hash-bang URL的默认哈希前缀已从空字符串('')更改为bang ('!').

The default hash-prefix used for $location hash-bang URLs has changed from the empty string ('') to the bang ('!').

如果您实际上不希望使用哈希前缀,则可以通过向应用程序中添加配置块来恢复以前的行为:

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

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

这篇关于角度网址添加了不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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