Vue下路由History mode 出现404,无法正常刷新

vue

在History mode下,如果直接通过地址栏访问路径,那么会出现404错误,这是因为这是单页应用(废话)…其实是因为调用了history.pushState API 所以所有的跳转之类的操作都是通过router来实现的,解决这个问题很简单,只需要在后台配置如果URL匹配不到任何静态资源,就跳转到默认的index.html。具体配置如下:

Apache

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.html$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.html [L]

</IfModule>

nginx

location / {

try_files $uri $uri/ /index.html;

}

 参考:https://blog.csdn.net/xjlinme/article/details/74783887

以上是 Vue下路由History mode 出现404,无法正常刷新 的全部内容, 来源链接: utcz.com/z/377281.html

回到顶部