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

Back button broken in Chrome when setting location.href in HTML5 mode #11667

Closed
circlingthesun opened this issue Apr 21, 2015 · 14 comments
Closed

Comments

@circlingthesun
Copy link

When clicking a link from http://example.com/ to http://example.com/app where /app runs angular with HTML5 mode and the baseURL set to /app, the following error is raised when you press the back button:

Error: [$location:ipthprfx] Invalid url "http://example.com/", missing path prefix "http://example.com/app/"

The offending line:
var pathUrl = beginsWith(appBaseNoFile, url);

Can be found here:

var pathUrl = beginsWith(appBaseNoFile, url);

pathUrl returns undefined which results in an error being thrown and the page not navigating back to http://example.com/ as expected.

@bruunofco
Copy link

Hello,
Displays the script that you are using to return the page.
And send an example in Plunker your code so we can better help you.

@circlingthesun
Copy link
Author

I've reproduced this here: http://public.jacklab.co.za/

@circlingthesun
Copy link
Author

Click the link, then click back.

@circlingthesun
Copy link
Author

In reproducing this I noticed that this only happens when the next page is navigated to by setting window.location.href. The reason for doing this is that the router at / sometimes intercepts links pointing to pages under the router at /app. Setting window.location.href allows me to bypass the router at /.

@circlingthesun
Copy link
Author

Also, this error does not happen in Firefox. I've only confirmed the bug in chrome 41.

@circlingthesun circlingthesun changed the title Back button broken when using HTML5 mode and baseURL. Back button broken in Chrome when setting location.href in HTML5 mode Apr 22, 2015
@Narretz Narretz added this to the 1.4.x - jaracimrman-existence milestone May 6, 2015
@Narretz
Copy link
Contributor

Narretz commented May 6, 2015

@petebacondarwin I assigned you since you said you where looking into location issues, hope that's okay.

@petebacondarwin
Copy link
Member

@circlingthesun - I think we may have fixed this bug in 6903b5e.

I copied down your reproduction of the issue to localhost but I couldn't get it to fail. Are you doing something clever on your server?

Can you try out the version at https://code.angularjs.org/snapshot?

@circlingthesun
Copy link
Author

I just updated the code to point the snapshot but the error still happens. I'm not doing anything fancy on the server. The site resolves to index.html and /app resolves to app.html. My nginx config is as follows:

server {
    root /home/rickert/Public;
    server_name public.*;

    location / {
        autoindex on;
    }

    location /app {
        try_files /app.html =404;
    }
}

@petebacondarwin
Copy link
Member

OK, so here is a failing Plunker: http://plnkr.co/edit/wQ7WxkIPTL1L8p5VnkxR?p=preview

@petebacondarwin
Copy link
Member

If you use target="_self" then you don't need the window.location.href hack and there is no error.
See http://plnkr.co/edit/szmCMV1j8HWSM9ODdmb3?p=preview

@circlingthesun
Copy link
Author

That'll work when there is a link. In my actual codebase I have a login modal that redirects to /app. Is there perhaps another way to get around this?

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Jul 16, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes angular#11667
@petebacondarwin
Copy link
Member

@circlingthesun - can you take a look at my proposed fix: #12361

@petebacondarwin petebacondarwin modified the milestones: 1.4.3, 1.4.x, 1.4.4 Jul 16, 2015
@circlingthesun
Copy link
Author

This does appear to fix the issue. (see http://public.jacklab.co.za/)

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this issue Jul 16, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes angular#11667
petebacondarwin added a commit that referenced this issue Jul 16, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes #11667
@petebacondarwin
Copy link
Member

Closed by 9e492c3

netman92 pushed a commit to netman92/angular.js that referenced this issue Aug 8, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes angular#11667
petebacondarwin added a commit that referenced this issue Sep 7, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes #11667
ggershoni pushed a commit to ggershoni/angular.js that referenced this issue Sep 29, 2015
Previously, if you navigate outside of the Angular application, say be clicking
the back button, the $location service would try to handle the url change
and error due to the URL not being valid for the application.

This fixes that issue by ensuring that a reload happens when you navigate
to a URL that is not within the application.

Closes angular#11667
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants