单页面应用的vue项目,设置router模式为history。能够跳转但刷新了页面,则显示为404。
vue-router的默认hash模式使用URL的hash来模拟一个完整的URL,当URL改变时,页面不会从新加载。可是这种hash很丑,也不符合对URL的使用习惯。因此,须要使用另一个叫history模式来实现URL跳转而无须从新加载页面。
export default new Router({ mode: "history", routes: [# other code ] )}
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>
location / { try_files $uri $uri/ /index.html; }