Q. Why using AngularJS it has #!/ (bang prefix) in URL?

If the browser is HTML5 browser angularJS will redirect it to #!

Otherwise it will be only #.

Q. How to remove #!/ (bang prefix) from URL?

Remove ! by using hashPrefix()
var myApp = angular.module('myApp', ['ui.router', 'ui.bootstrap']); 

myApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {

    // remove ! from url
    $locationProvider.hashPrefix('');
If you want to remove the whole prefix (# and not only !)

1) Activate the HTML5 mode and remove the prefix ! in your module config

Note: 一些舊的Browser並不支援HTML5, 開啟HTML5模式, 會造成一些問題. 不過已經很少了

$locationProvider.html5Mode(true); 
$locationProvider.hashPrefix('');

2) And then set base to / in the <head> on yourindex.html

<head>
    ...
    <base href="/">
</head>

Note: 移除#後, 一些原本client端的routing會失效, 這個還要再找時間研究

results matching ""

    No results matching ""