角度路线包含#!在网址而不是# [英] Angular routes contain #! in the url instead of #

查看:176
本文介绍了角度路线包含#!在网址而不是#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我注意到在AngularJS应用程序中使用 ngRoute 模块时,路径中包含#! URL,之前只是



例如, www.webiste。 com /#/ login 变为 www.website.com /#!/ login



我必须启用 html5Mode 并禁用 requireBase ,它使用代码整体删除基数,

  $ locationProvider.html5Mode({
enabled:true,
requireBase:false
}) ;

并且网址更改为 www.website.com/login 哪个工作正常但有误导性,而不是Angular SPA网址的样子。



如果我没有启用 html5Mode ,URL已编码,我无法绕过它。所以 www.website.com /#/ login 变成 www.website.com /#!/#%2Flogin (请注意,后面的 / 编码为%2F )。



<这是开发人员为某些特定目的而实施的变更吗?它有什么不同?我需要对应用程序进行哪些更改才能使其正常运行?我做错了吗?



Github问题: https: //github.com/angular/angular.js/issues/15547

解决方案

它被称为哈希爆炸。



有一段时间Twitter使用相同的东西。它允许AJAX调用,让搜索引擎知道你的路径而不使用真实路径。但它被认为是过时的。



https://developers.google.com/webmasters/ajax-crawling/docs/getting-started



还有另一个stackoverflow答案那:



做Twitter,Hash-Bang#等链接!网址


Recently I have noticed that when using ngRoute module in an AngularJS app, the route contains #! in the URL, which was earlier just the #.

For example, www.webiste.com/#/login becomes www.website.com/#!/login

I have to enable the html5Mode and also disable the requireBase which removes the base as a whole using the code,

$locationProvider.html5Mode({
       enabled: true,
       requireBase: false
});

and the URL changes to www.website.com/login which works fine but is misleading and is not what Angular SPA URLs look like.

If I do not enable the html5Mode, the URL is encoded and I cannot get around it. So www.website.com/#/login becomes www.website.com/#!/#%2Flogin (Notice the later / is encoded as %2F).

Is this a change implemented by the developers for some specific purpose? What difference does it make? What changes do I need to make to my app to keep it working? Am I doing something wrong?

Github issue: https://github.com/angular/angular.js/issues/15547

解决方案

It's called the hash bang.

For a while Twitter was using the same thing. It allows for AJAX calls and let search engines know your path without using a "real" path. It's considered obsolete though.

https://developers.google.com/webmasters/ajax-crawling/docs/getting-started

There is another stackoverflow answer about that:

Doing links like Twitter, Hash-Bang #! URL's

这篇关于角度路线包含#!在网址而不是#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆