angularjs 应用程序中哈希(#!)后的感叹号 [英] Exclamation mark after hash (#!) in angularjs app

查看:25
本文介绍了angularjs 应用程序中哈希(#!)后的感叹号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到我的所有路由中的哈希 (#!) 后面都有一个感叹号.我不确定我是如何以及为什么得到它们的,因为今天早些时候我没有它们.

I have just noticed that I have an exclamation mark after a hash (#!) in all of my routes. I'm not sure how and why I got them because earlier today I didn't have them.

如果有任何解决方案可以摆脱它们,如果有人能向我解释它是什么(以及我是如何拥有它们的),我将不胜感激.

If there is any solution to get rid of them, I would appreciate if someone can explain me what is it( and how I came to have them).

所以,到目前为止,我找到的唯一解决方案是在我的应用程序中的每个 href 上手动放置感叹号,但这让我很恼火,我不知道该怎么做.

So, the only solution that I have found so far is to put manually put the exclamation mark on every href in my app, but this annoys me and I have no idea what to do.

我使用 yeoman 生成器生成了我的应用程序,我的 app.js 如下所示:

I generated my app with yeoman generator and my app.js looks like this:

angular
  .module('appNameApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl',
        controllerAs: 'main'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'AboutCtrl',
        controllerAs: 'about'
      })
      .when('/jaspo', {
        templateUrl: 'views/about.html',
        controller: 'jaspoCtrl',
        controllerAs: 'vm'
      })
      .otherwise({
        redirectTo: '/'
      });
  });

推荐答案

修改这两行:

  .config(function ($routeProvider) {
$routeProvider

成为:

    .config(function ($routeProvider,$locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider

信用应该转到:https://stackoverflow.com/a/41223197/1564146

这篇关于angularjs 应用程序中哈希(#!)后的感叹号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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