我使用的是棱角分明,而我的网址始终带有“!" (感叹号) [英] I am using angular, and my url always has a "!" (exclamation mark)

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

问题描述

例如:

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模式是AngularJS用于向您的Angular提供深度链接功能的一种技巧 应用.在hashbang模式(对于html5模式的后备)中,URL路径使用前置的#字符. 它们不重写标签,不需要任何服务器端支持.哈希邦 如果没有其他说明,则模式是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模式,需要在 应用模块

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