2

I just noticed that for some reason, I get this:

http://localhost/ReportsWeb/#!/

instead of this: http://localhost/ReportsWeb/#/

exclamation sign is added... why, any ideas, cant figure the reason why its where.

Obviously, if I navigate to http://localhost/ReportsWeb, the URL becomes http://localhost/ReportsWeb/#!/

UPDATE

Thanks guys for the help. These two options work fine:
1)
set $locationProvider.html5Mode(true)
add <base href="/ReportsWeb/">
2)
set $locationProvider.html5Mode(false);
set $locationProvider.hashPrefix('');

Which option is "more correct" way to handle this?

To me the second option looks right, I dont need to make any more changes to make my project work. In first case, I need to set base element, but angular routing wont work, I probably have to change all "/#/Path" to exclude the hash tag. So, I'll take option #2 )

thanks

monstro
  • 6,254
  • 10
  • 65
  • 111
  • 1
    Possible duplicate of [Why does my url contains "!" when using angular?](http://stackoverflow.com/questions/42033863/why-does-my-url-contains-when-using-angular) – Pritam Banerjee Feb 08 '17 at 00:55
  • @Pritam Banerjee, it is similar, but not duplicate, I need to know the difference between these two options – monstro Feb 08 '17 at 01:09

2 Answers2

3

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://localhost/ReportsWeb/#!/

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.

angular.module('myApp', ['ngRoute'])
    .config(['$locationProvider', function($locationProvider) {
           $locationProvider.html5Mode(false);
           $locationProvider.hashPrefix('');
}]);
Yaser
  • 5,609
  • 1
  • 15
  • 27
2

Try this, should work. You need to set html5Mode to true where you're handling your angular routes, here's some example code of what your app should look like

var myApp = angular.module('myApp', ['ngRoute'])
myApp.config(function ($routeProvider, $locationProvider) {
  $routeProvider
    .when('/', {

    })
    .otherwise({redirectTo: '/'})

  $locationProvider.html5Mode(true)
})
Roadhouse
  • 41
  • 6