Skip to content

Instantly share code, notes, and snippets.

@Slauta
Created June 9, 2021 10:58
Show Gist options
  • Save Slauta/c85dee1ad7b3042770e4feb5b9b81c3e to your computer and use it in GitHub Desktop.
Save Slauta/c85dee1ad7b3042770e4feb5b9b81c3e to your computer and use it in GitHub Desktop.
Vue History Mode routing Nginx config example

HTML5 History Mode

The default mode for Vue Router is hash mode. It uses a URL hash to simulate a full URL so that the page won’t be reloaded when the URL changes.

We can set Vue Router to history mode to get rid of the hash. It uses history.pushState API to let us navigate URLs without a page reload.

This configuration allows you to configure nginx to work with Router History on the server side.

server {
server_name mysite.com;
listen 80;
charset utf-8;
root /var/www;
location @rewrites {
rewrite ^/(.*)$ /index.html last;
}
location / {
charset utf-8;
try_files $uri $uri/ @rewrites;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment