我正在使用角度,我的网址总是有一个“!"(感叹号) [英] I am using angular, and my url always has a "!" (exclamation mark)

查看:16
本文介绍了我正在使用角度,我的网址总是有一个“!"(感叹号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

http://localhost/#!/login.html

我不需要!".我将如何删除它?

I don't need "!". How would I remove it?

eg:http://localhost/#/login.html

这是我的路由器代码:

  // Redirect any unmatched url
$urlRouterProvider.otherwise("/login.html");
$stateProvider.state('login', {
    url: "/login.html",
    templateUrl: "views/login.html",
    data: {pageTitle: "login", isLeft: false},
    controller: "LoginCtrl",
    resolve: {
        deps: ['$ocLazyLoad', function ($ocLazyLoad) {
            return $ocLazyLoad.load({
                name: 'myApp',
                files: [
                    'controllers/LoginCtrl.js'
                ]
            });
        }]
    }
});

我认为Angular-ui-router可能有问题,但我找不到解决方案.

I think Angular-ui-router might have a problem, but I can't find the solution.

谢谢!

推荐答案

Hashbang模式

Hashbang 模式是 AngularJS 用来为 Angular 提供深度链接功能的技巧应用.在 hashbang 模式(html5 模式的后备)中,URL 路径采用前置 # 字符.它们不会重写标签,也不需要任何服务器端支持.哈希邦mode 是 AngularJS 使用的默认模式,如果没有另外说明的话.hashbang URL 如下所示:

Hashbang mode is a trick that AngularJS uses to provide deep-linking capabilities to your Angular apps. In hashbang mode (the fallback for html5 mode), URL paths take a prepended # character. They do not rewrite tags and do not require any server-side support. Hashbang mode is the default mode that AngularJS uses if it’s not told otherwise. A hashbang URL looks like:

http://yoursite.com/#!/inbox/all

要显式配置 hashbang 模式,需要在 config 函数中配置应用模块

To be explicit and configure hashbang mode, it needs to be configured in the config function on an app module

我们还可以配置 hashPrefix,在 hashbang 模式下,它是!字首.这个前缀是 Angular 的后备机制的一部分用于较旧的浏览器.我们也可以配置这个字符.

We can also configure the hashPrefix, which, in hashbang mode, is the ! prefix. This prefix is part of the fallback mechanism that Angular uses for older browsers. We can also configure this character.

配置 hashPrefix:

angular.module('myApp', ['ngRoute'])
.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
}]);

这篇关于我正在使用角度,我的网址总是有一个“!"(感叹号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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