0

I updated angularjs to 1.2.0-rc1 and added in ng-route as a dependency and added the angular-route.js file. In this build it is now separate.

Clicking on a link for example that has a bookmark href assigned which i used for bootstrap..

 href="#collapse1"

Now angularjs is actually trying to change the route to #/collapse1

Is this a bug or am i missing something

Can anyone help?

Is there some additional configuration that i need to do to stop this from happening ?

Expected behavior

The expected behavior is what happens in angular before (i think i was using 1.0.8) ... the link does nothing as far as angularjs is concerned i.e. NO ROUTE CHANGE, of course bootstrap picks does its own thing and shows an accordion in this example.

Martin
  • 23,844
  • 55
  • 201
  • 327

2 Answers2

1

This angularjs feature. Use

href="#/#collapse1"

for correct location change.

DimaOverflow
  • 1,513
  • 1
  • 16
  • 18
  • Hi Dmitry, thanks for the reply.But I don't want a location change. This is a standard bookmark type href i.e. href="#collapse1" ... In 0.0.8 (the version I used before), clicking it did nothing but of course bootstrap picks that up and does some special stuff with it for the accordion. The problem is now... It actually causes a route change in angularjs.. But this is not expected behavior. – Martin Aug 29 '13 at 13:27
  • Sorry I meant to say 1.0.8 :-) – Martin Aug 29 '13 at 13:35
  • Can you enable html5mode? If use prefix, you links should be work. `app.config(function ($locationProvider) { $locationProvider.html5Mode(true).hashPrefix('!'); });` – DimaOverflow Aug 29 '13 at 13:50
  • the browser bar still displays http://localhost:9000/#collapse1 and the route is still changing. Has something changed between 1.0.8 and the new version ? – Martin Aug 29 '13 at 13:54
  • Its very strange, I have rolled back to 1.0.8 and it functions as expected. Also with regards to enabling html5mode, i probably want to go with backward compat – Martin Aug 29 '13 at 13:55
  • Hmm, that's weird. I checked on my project, and links do not lead to a change of location. At the same time I turned on the html5mode and added prefix, as I wrote above. By clicking on the link href="#test" hash is just added into the address bar. AngularJS v1.2.0rc1 – DimaOverflow Aug 29 '13 at 14:06
  • Hi Dimitry, yes this is the case here too, but surely it shouldn't add the hash into the location bar ? Can you confirm that without adding the htm5mode you get a location change too ?? These are standard bookmark HREFs that should not cause a route change - should they ? – Martin Aug 29 '13 at 14:13
  • My bootstrap isn't working, as a route change happens and ng-route redirects to /, if i enable html5mode then the routechange doesn't seem to happen but the location bar changes.. – Martin Aug 29 '13 at 14:13
  • So far I have found only one solution, and it is very ugly. You want to change the standard function $$parse in the angualar.js file. [http://pastebin.com/zrfLjnpj](http://pastebin.com/zrfLjnpj) And you would still need to use a prefix. `$locationProvider.hashPrefix('!');` – DimaOverflow Aug 29 '13 at 14:21
  • Thanks Dimitry for all your help on this, yep changing the angularjs file is something i didn't want to do. So the way it works now is classed as a bug ? It will be fixed? or no more using #something which seems rather limiting ? I wondering if i should go back to 1.0.8 where at least it works but then of course if it never gets addressed i would be stuck in the past for ever without ability to upgrade :-)!! – Martin Aug 29 '13 at 14:26
  • I think it's not a bug, but part of the ideology angular, because the kernel checks for correctness url links. Unfortunately all Frameworks can have problems with individual modules. – DimaOverflow Aug 29 '13 at 14:31
  • Thanks for the update, i want to accept your answer, but currently the answer is wrong, do you want to update teh answer stating that this is how angular works currently, no work arounds currently and I will accept. – Martin Aug 29 '13 at 15:07
0

because i had the same problem. At my point Bootstrap wasn't loaded and so he tried to route this collaps as an route. After i loaded bootstrap manuel to this view, it works fine.

Hope you understand my bad english ;)