Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs $location.hash makes ##, but i need #

Tags:

url

angularjs

AngularJS 1.2.0 (but lower versions have the same problem)

I have a web app with some widgets and want to save their state into URL. I do this now with $location.hash('param1=1&param2=678') command. But I get url like: domain.com/##param1=1&param2=678 It works ok, I can restore state of my app. One problem I have with that is when someone click such a link in, for example, mail app, their browser encodes one of hashes with /23 and so my app goes wrong. How can i solve this? Thanks

Here is plunk: http://plnkr.co/edit/VVjEUzROou6hu8B8sURa?p=preview You need open it in new window to able to test hashes

like image 969
outluch Avatar asked Oct 08 '13 16:10

outluch


Video Answer


2 Answers

for standard hash locations in angular, you use

location.path("myappstate/1");

as angular is set up to think of first hash state as the primary url or path for the app. The location.hash() setups a secondary hash on the primary hash state (path)

like image 79
chrismarx Avatar answered Oct 13 '22 23:10

chrismarx


This is not the best answer, but you could try to inject $locationProvider and set:

$locationProvider.html5Mode(true);

That way angular runs in HTML5 mode and it does not use hashbangs. I recommend this SO question for more info.

like image 35
Capaj Avatar answered Oct 13 '22 23:10

Capaj