visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

shows 404 error on browser refresh #414

Closed iiison closed 6 years ago

iiison commented 7 years ago

Hi, my browser shows 404 error if URL is not /. I know server should redirect all get requests with /. I was wondering if this could be handled at Front-End level. Like react-router does.

Shyam-Chen commented 7 years ago

Try connect-history-api-fallback or express-history-api-fallback.

paulocoghi commented 7 years ago

The solution posted by @Shyam-Chen only works when you are using a tool like Browser Sync.

If using Apache, create a .htaccess file in the root of your project directory with this:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ ./index.html

If using Nginx, add this to the .conf file related to your project (inside the "server" part):

location / {
    try_files $uri =404;
    try_files $uri $uri/ index.html;
}
matthewp commented 6 years ago

Sounds like this is a backend issue, closing.