Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.js add #%2F on URL when set $locationProvider.html5Mode(true).hashPrefix('!')

Tags:

angularjs

After configure: $locationProvider.html5Mode(true).hashPrefix('!') when i enter url : www.example.com/search on browser(chrome) and press enter then it turn into : www.example.com/#%2Fsearch and then go to home page.

when i click on the link like <a href="/search" /> then its work. if i remove .hashPrefix('!') then also works fine. But i need that hashPrefix('!')

Any idea how could i solve this?

like image 409
muktadiur Avatar asked Aug 11 '14 18:08

muktadiur


People also ask

Can I use Angular with JavaScript?

Yes. Angular does use . ts files by default. But if you write simple javascript code in them it will still work.

What is AngularJS file extension?

AngularJS extends HTML with ng-directives.


2 Answers

This was happening to me because all my links had a "#" on them, like in www.example.com/search/#/xxx/yyy. When clicked, it would take you to www.example.com/search/#%2Fxxx%2Fyyy. So I just removed them and the problem disappeared.

like image 153
Thiago Duarte Avatar answered Oct 29 '22 20:10

Thiago Duarte


I know this is an old post and the problem has already been solved. I had the same issue with an application I was working, but, in my case, we should keep the '#'. So, all I did was add the following line:

$locationProvider.html5Mode(false).hashPrefix('');

Don't forget to modify your .config arguments if you haven't done it already, like this:

.config(function($routeProvider, $locationProvider)
like image 27
Henrique Caúla Avatar answered Oct 29 '22 20:10

Henrique Caúla