Caue,
Sander,
thanks for the helpful answers. So your idea was to rewrite the <a> tags
before Angular rewrites them. I did it this way (Solution A):
.directive('a', function() {
return {
priority : 9999,
restrict : 'E',
link : function(scope, element, attrs) {
element.attr("target", "_self");
}
};
})
A less stupid implementation would check if the 'target' attribute already
exists, and somehow disambiguate 'new' links that should be processed by
Angular. Anyways, the old links seem to work again with this approach.
However it feels a bit risky - since I would be rewriting thousands of
links. My gut instinct is to avoid this kind of impact.
I'd rather turn the 'rewriteLinks' html5Mode feature off and use a special
directive that renders new links over which I have full control (Solution
B), i.e.:
<link path='/new'></link>
which compiles to
<a href="/new" onClick='return false;' ng-click="navigate('/new')"
path="/new">LINK</a>
The directive's controller would call $location.path(path) in the
navigate() function. I tried to demonstrate it here, but it does not work
in plunker: http://plnkr.co/edit/H5t9JctXh6OEQYjoFHfY?p=preview
It seems to work in my context though. It needs some cleanup, but using a
special directive has the added benefit that I can easily change all newly
created links in case I need to switch to another solution (still thinking
about hashbang urls).
onClick + ng-click looks awful but it works. Otherwise clicks cause server
requests and kill the SPA even if the route gets triggered correctly.
Writing all this down actually helped me understand it. Thanks for
listening ;-) Maybe this will help someone in a similar position.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.