我使用角度,我的网址总是有一个"!" (感叹号)

Alw*_*ayS 12 angularjs angular-ui-router

例如:

http://localhost/#!/login.html
Run Code Online (Sandbox Code Playgroud)

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

eg:http://localhost/#/login.html
Run Code Online (Sandbox Code Playgroud)

这是我的路由器代码:

  // 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'
                ]
            });
        }]
    }
});
Run Code Online (Sandbox Code Playgroud)

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

谢谢!

Jig*_*521 7

哈什邦模式

Hashbang模式是AngularJS用于为Angular应用程序提供深层链接功能的技巧.在hashbang模式(html5模式的后备)中,URL路径采用前置#字符.它们不会重写标记,也不需要任何服务器端支持.Hashbang模式是AngularJS使用的默认模式,否则不会被告知.hashbang URL如下所示:

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

要显式并配置hashbang模式,需要在app模块的config函数中进行配置

我们还可以配置hashPrefix,在hashbang模式下,它是!字首.此前缀是Angular用于旧版浏览器的回退机制的一部分.我们也可以配置这个角色.

要配置hashPrefix:

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