vue下history模式刷新后404错误解决方法
作者:linvic 时间:2024-04-27 15:47:56
本文介绍了vue下history模式刷新后404错误解决方法,分享给大家,具体如下:
官方说明文档:
https://router.vuejs.org/zh/guide/essentials/history-mode.html
一、 实测 Linux 系统 Apache 配置:
更改站点配置文件即可,我这里在 Directory 标签后面添加了官方给的五行配置
<VirtualHost *:80>
#Created by linvic on 2018-05-24
Serveradmin 674206994@qq.com
ServerName blog.xxx.com
DocumentRoot /home/www/blog
<Directory "/home/www/blog">
Options FollowSymLinks
AllowOverride All
#Require all denied
Require all granted
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</Directory>
</VirtualHost>
二、 实测 Windows 环境下 IIS 配置
1. IIS安装Url重写功能
https://msdn.microsoft.com/zh-cn/gg192883.aspx
到该网站下载安装web平台安装程序
安装后打开到里面搜索安装URL重写功能
2. web.config
将web.config 文件放置于 npm run build 打包后文件的根目录即可。
ps:此文件会自动给IIS上的URL重写功能进行相关配置
文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".ttf" mimeType="font/x-ttf" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="text/json" />
</staticContent>
<rewrite>
<rules>
<rule name="vue" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
来源:https://segmentfault.com/a/1190000016050854
标签:vue,history模式,404
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ACCESS中Field对象的标题属性
2008-11-20 17:44:00
vue上传图片组件编写代码
2024-05-10 14:14:33
![](https://img.aspxhome.com/file/2023/2/126542_0s.jpg)
Python函数值传递引用传递及形式参数和实际参数的区别
2022-06-23 13:07:51
Python线程之定位与销毁的实现
2023-09-25 11:47:19
![](https://img.aspxhome.com/file/2023/1/90851_0s.png)
彻底终结浏览器Cache页面的解决方案
2008-04-21 15:10:00
Python抽象类应用详情
2022-03-24 17:41:13
![](https://img.aspxhome.com/file/2023/9/99229_0s.png)
vscode使用chatGPT 的方法
2022-10-10 15:55:38
![](https://img.aspxhome.com/file/2023/8/104958_0s.png)
asp.net得到本机数据库实例的两种方法代码
2024-01-27 16:00:42
python可视化plotly 图例(legend)设置
2021-05-17 11:17:56
![](https://img.aspxhome.com/file/2023/4/134474_0s.png)
vue使用canvas绘制圆环
2024-05-02 17:04:29
![](https://img.aspxhome.com/file/2023/6/130066_0s.jpg)
利用Python将list列表写入文件并读取的方法汇总
2023-12-07 13:40:07
![](https://img.aspxhome.com/file/2023/4/95164_0s.png)
C#Web应用程序入门经典学习笔记之二
2024-06-05 09:28:00
SQL Server 2005中的CLR集成
2009-03-10 15:07:00
asp如何让用户也能修改密码?
2010-05-13 16:41:00
go语言map字典删除操作的方法
2024-02-03 16:19:37
CentOS7.3下mysql 8.0.13安装配置方法图文教程
2024-01-23 09:42:10
详解MySQL下InnoDB引擎中的Memcached插件
2024-01-24 22:02:35
功能强大,代码简单的管理菜单
2008-07-11 16:52:00
JavaScript 放大镜 移动镜片效果代码
2023-08-13 08:24:08
Tensorflow实现卷积神经网络的详细代码
2022-02-20 22:14:06