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

2019-06-11 22:07发布

This question already has an answer here:

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条回答
Emotional °昔
2楼-- · 2019-06-11 22:43

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.

查看更多
登录 后发表回答