page.js icon indicating copy to clipboard operation
page.js copied to clipboard

Manually changing the URL causes 404 when using Hasbang=true mode

Open sshadmand opened this issue 9 years ago • 6 comments

To reproduce:
  • Run the examples project "Basic"
  • Click the "Contact Me" URL
  • You will now have "/basic/#!/contact/me" as the URL path
  • Now, manually remove the "/me" from the address bar's URL. Press enter to load the URL
Current Result:
  • Nothing happens
  • Press enter again in the address bar and the page loads properly
Expected Result:
  • /basic/#!/contact should load the corresponding page on first attempt.

If you add a catch all to the Basic example:

     /* CATCH ALL */
    page('*', function (argument, next) {
        console.log("404", argument, next);
    });

you will find the "404" page is triggered upon the first attempt to change the URL address manually.

sshadmand avatar Jul 07 '15 10:07 sshadmand

I'm running into the same issue. When I'm browsing posts in my app, the URLs look like this: http://localhost:3000/#!/post/id But I get 404 when I enter such an URL manually.

How can this be fixed?

This has to work. Users often copy/paste URLs!

Boscop avatar Jan 23 '17 23:01 Boscop

This also happens to me. When I am using live reload or any other thing to reload while I am developing. After each save page is reloaded but I get 404

gokhandemirhan avatar Mar 24 '18 20:03 gokhandemirhan

@gokhandemirhan and @Boscop , please read the new section "Server Configuration". There are instructions that also serve for "live reloaders".

Everything based in nodejs, including live reloaders, can benefit from "history-api-fallback" to avoid 404 when reloading URL's.

paulocoghi avatar Mar 25 '18 19:03 paulocoghi

I'm not using nodejs and I'm not talking about livereload. I mean when the user in the browser pastes that URL and hits Enter, they get 404, how to fix that?

Boscop avatar Mar 26 '18 09:03 Boscop

@Boscop, what webserver you are using? If it is Apache or Nginx, there are instructions for them as well in the new section I mentioned.

paulocoghi avatar Mar 26 '18 23:03 paulocoghi

The request isn't even sent to the server, the 404 happens in the client-side routing in page.js..

Boscop avatar Mar 27 '18 01:03 Boscop