自从我上次工作在AngularJS项目中时,我的URLs已经从 localhost:3000/admin#/
变成了 localhost:3000/admin#!/
...
在网上没有找到任何相关信息,有人知道这是什么吗?
自从我上次工作在AngularJS项目中时,我的URLs已经从 localhost:3000/admin#/
变成了 localhost:3000/admin#!/
...
在网上没有找到任何相关信息,有人知道这是什么吗?
AngularJS 1.6新增了一个新的哈希前缀。
由于aa077e8,用于
$location
哈希bang URL的默认哈希前缀已从空字符串(''
)更改为感叹号('!'
)。如果您的应用程序没有使用HTML5模式,或者在不支持HTML5模式的浏览器上运行,并且您没有指定自己的哈希前缀,则客户端URL现在将包含一个!
前缀。例如,URL将变为mydomain.com/#!/a/b/c
而不是mydomain.com/#/a/b/c
。
有关详细信息,请参见此处的来源。
如果要删除此前缀,请将以下代码添加到配置文件中:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
大家都在提议去掉URL前缀,但你也可以在客户端URL中加上!
(如果不使用HTML5模式的话,您可能正在使用它)。
因此,在您的客户端文件中,像这样更新URL:
#/foo/bar
> #!/foo/bar
<rewrite>
<rules>
<rule name="angular cli routes" stopProcessing="true">
<match url=".*"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
</conditions>
<action type="Rewrite" url="/"/>
</rule>
</rules>
</rewrite>
之后,一切正常
#
来声明路由参数看起来有点奇怪。你可能想使用更常见的路由格式,比如/callback/BD55C7FD4F129A9CAC1506E225EF9149
或/callback?code=BD55C7FD4F129A9CAC1506E225EF9149
。
此外,这里有一个很好的SO答案,介绍了将参数传递到AngularJS路由的不同方法:https://dev59.com/f18e5IYBdhLWcg3whqzl#25647714 - Pierre C.