angular ui-router时要使用html5Mode=true

为什么我们要在使用angular ui-router时要使用html5Mode=true这个呢?

在angular中,你在访问链接时,可能访问的链接为"#/link".

如果你设置了html5Mode=true时,这个时候页面就会重定向到"/link"这个页面中。

如果设置html5Mode=false, 在访问的时候就需要在链接前面加上"#/link"这样的符号。

所以,设置html5Mode=true不会影响你的html5代码,只是为了访问的时候更加地方便。

在app.config配置文件中添加$locationProvider.html5Mode(true).hashPrefix('!')配置信息。

需要在页面的入口文件,也就是index.html中设置<base href="/">

原文地址:https://www.cnblogs.com/hjsblogs/p/8405243.html