0

I have read lots of other related posts, but cannot understand what's wrong with the following code:

$(window).on("beforeunload", function () {
    debugger
    handleBeforeUnload();
    return false;
});
function handleBeforeUnload() {
    if (location.pathname != "/") {
        location.assign(location.hostname + "/#" + location.pathname);
    }
}

I have also tried a pure JavaScript approach without success. The underlying problem I am trying to solve is with angular "pretty" URLs. Although clicking links work fine, when reloading a page (ex. mydomain.com/about) I get a 404 Not Found error. I found that manually inserting a hashbang (mydomain/#/about) works correctly.

What am I missing here?

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
ron tornambe
  • 10,452
  • 7
  • 33
  • 60
  • Although it is a similar question, it did not give a specific answer for my platform (Apache) – ron tornambe Jun 18 '16 at 15:56
  • 1
    You didn't ask a specific question for your platform... – Alexander O'Mara Jun 18 '16 at 15:57
  • http://stackoverflow.com/questions/22739455/htaccess-redirect-for-angular-routes, http://stackoverflow.com/questions/14168836/refreshing-page-gives-page-not-found, http://stackoverflow.com/questions/14319967/angularjs-routing-without-the-hash, http://stackoverflow.com/questions/34411206/multiple-htaccess-rewrite-conditions-angular-routes-html5-mode – Alexander O'Mara Jun 18 '16 at 16:02
  • Thanks, but neither of those solutions work for me. – ron tornambe Jun 18 '16 at 16:18

1 Answers1

1

What am I missing here

Your whole higher level problem stems from not configuring server to always serve the app entry point when you are using html5Mode pretty URL's

Server has no knowledge of the virtual directories that the client side app uses unless you configure it

charlietfl
  • 170,828
  • 13
  • 121
  • 150