AngularJS ui-router application has /#!/ in the UR

2019-06-11 22:49发布

问题:

This question already has an answer here:

  • URL hash-bang (#!/) prefix instead of simple hash (#/) in Angular 1.6 3 answers

I have an application with ui.router working normally, but another application the url has an "!" after "#"

Ex: http://localhost:8090/dev/#!/home

Why it happens?

The normal should be: http://localhost:8090/dev/#/home

回答1:

I suppose this happens because hashprefix is not set.

$locationProvider
  .hashPrefix('!');

I guess you can set it to empty string and that is why you don't see !.

Alternatively you can enable html5modethat will get rid ofhashbang` completely. Some older browsers don't support it, but generally not an issue, unless you need to support IE9 or something.

You can read about it e.g. here or here.

Long story short if you configure html5mode properly, then you won't have the hashbang that is required for routing in older browsers that do not support it.