Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Links to outside of Angular application are getting overridden #1051

Closed
andyneville opened this issue Jun 13, 2012 · 13 comments
Closed

Links to outside of Angular application are getting overridden #1051

andyneville opened this issue Jun 13, 2012 · 13 comments

Comments

@andyneville
Copy link

When I create a relative link to a page outside of my single page Angular app (e.g. <a href="/foo/bar">Click</a>), there appears to be an Angular click handler which intercepts this link and won't let me follow it.

To recreate this in Angular seed (rc12):

  1. create a file in the app folder called "test.html", put something in it you can recognize:
<html><body>Test</body></html>
  1. In partials/partial1.html, add this line:
<a href="/test.html">test</a>
  1. Open the site in a browser (http://localhost:4000/ for me using a simple node app). It redirects me to http://localhost:4000/#/view1 which looks fine.

  2. Click on the "test" link, which should take you to the http://localhost:4000/test.html page. Instead, I see a brief flicker in the address bar and it just goes back to http://localhost:4000/#/view1

I'm in Chrome if that matters.

@andyneville
Copy link
Author

FYI this worked fine in RC10

@IgorMinar
Copy link
Contributor

we are looking into this.

@mhevery
Copy link
Contributor

mhevery commented Jun 13, 2012

I am trying to reproduce this but having no luck. Could you create a simple test file and email it to me? Here is a starting point: https://gist.github.com/2925715

Your description is baffling. A click on the link is either .preventDefault() or do nothing. In other words we either handle the request ourselves and prevent the browser navigation, or we let the browser do its normal thing. In your case you are seeing flicker. This is strange since it would mean that you would have the browser change the URL, but then redirect back. There is no way to redirect back in JS once you leave the page as far as I know.

In either case please provide a reproducible case, since i am unable to reproduce it.

@ejain
Copy link

ejain commented Jun 13, 2012

Add onclick="return false" to the link, and observe that the page URL changes when clicking the link. Replace rc12 with rc10, and the page URL no longer changes when clicking the link.

@andyneville
Copy link
Author

I sent you an email w/ my example based on the angular seed project, thanks for the help!

@ejain
Copy link

ejain commented Jun 13, 2012

Look at https://gist.github.com/2925818. Both the Foo and the Bar link ignore the onclick return false. Not injecting the $location service into the Foo controller changes the behavior of both the Foo and the Bar link (which now honor the return false)!

mhevery added a commit to mhevery/angular.js that referenced this issue Jun 14, 2012
@IgorMinar
Copy link
Contributor

can you guys test this build: http://ci.angularjs.org/job/angular.js-igor/623/artifact/build/pkg/1.0.0-199ee246/

it should contain a fix for this issue.

@mhevery mhevery closed this as completed Jun 14, 2012
@andyneville
Copy link
Author

So I just tested the 1.0.0-199ee246 build above, and the issue I was seeing around links being intercepted seems to be fixed.

However, a new issue popped up with this build with an unhandled exception. I have a jsFiddle at http://jsfiddle.net/AndyNeville/H5Jme/ based on Misko's example above that shows it happening. Open the jsFiddle (and open your Javasacript console), then change focus away from Chrome, and then focus (click) back into the jsFiddle "result" iframe. You should see Uncaught TypeError: Cannot call method 'indexOf' of undefined The exception is from angular.js, line 5012 (inside the this.$$rewriteAppUrl function), a call is being made to absoluteLinkUrl.indexOf, yet absoluteLinkUrl is null. I'll be glad to email a screen capture of the exception & callstack if that helps.

@andyneville
Copy link
Author

BTW, I just tested against the latest build, at http://ci.angularjs.org/job/angular.js-igor/627/artifact/build/pkg/1.0.0/, and I still see this exception

@ejain
Copy link

ejain commented Jun 14, 2012

1.0.0-199ee246 works for me, but I also see that error logged:

Uncaught TypeError: Cannot call method 'indexOf' of undefined angular-1.0.0-199ee246.js:5012
$$rewriteAppUrl angular-1.0.0-199ee246.js:5012
(anonymous function) angular-1.0.0-199ee246.js:5367
jQuery.event.dispatch jquery-1.7.2.js:3332
jQuery.event.add.elemData.handle.eventHandle

@andyneville
Copy link
Author

Thanks guys, the released 1.0.0 version seems to fix this for me, both in the fiddle and my own code. Congratulations on the release, I can't tell you how much we appreciate the work you've done on this fantastic library!!!

@ejain
Copy link

ejain commented Jun 14, 2012

1.0.0 seems to work with no issues for me as well (at least on Chrome, haven't tested across browsers yet). Good job!

@IgorMinar
Copy link
Contributor

Yay!

btford pushed a commit to btford/angular.js that referenced this issue Jun 15, 2012
mhevery added a commit to mhevery/angular.js that referenced this issue Apr 15, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants