Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

angularjs - I am using angular, and my url always has a "!" (exclamation mark)

For example:

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

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

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

This is my router code :

  // 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'
                ]
            });
        }]
    }
});

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hashbang Mode

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

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

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.

To configure the hashPrefix:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...