问题原因:

刷新页面时访问的资源在服务端找不到,因为vue-router设置的路径不是真实存在的路径

解决方案:

第一步:后端配置

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;
}

Native Node.js

const http = require("http")
const fs = require("fs")
const httpPort = 80 http.createServer((req, res) => {
fs.readFile("index.htm", "utf-8", (err, content) => {
if (err) {
console.log('We cannot open "index.htm" file.')
} res.writeHead(200, {
"Content-Type": "text/html; charset=utf-8"
}) res.end(content)
})
}).listen(httpPort, () => {
console.log("Server listening on: http://localhost:%s", httpPort)
}) 第二步:前端配置
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '*', component: NotFoundComponent }
]
})
-------------------------------------------------------------------------------------------------
如:
   // 404未找到
{
path: '*',
component: notFind,
meta: {
title: '404未找到',
},
},

Vue 404页面处理的更多相关文章

  1. vue 项目中当访问路由不存在的时候默认访问404页面

    前言: 在Vue项目中,当访问的页面路由不存在或错误时,页面显示为一片空白.然而,通常我们需要对访问url不存在或者错误的情况下添加默认的404页面,即not found页面. 一般的处理方法是: 在 ...

  2. nignx部署Vue单页面刷新路由404问题解决

    官网说明: https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E8%AD%A6%E5%91%8A 在linux下搭建ngi ...

  3. 066——VUE中vue-router之rewrite模式下配置404页面

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. vue+webpack 打包文件 404 页面空白

    最近用vue-cli+vue-router+webpack建立项目,其中的遇到的三个问题,整理如下: vue-cli+ webpack 建立的项目,cnpm run build 打包项目之后,需要放在 ...

  5. vue hash模式和404页面的配置

    1.设置我们的路由配置文件(/src/router/index.js): { path:'*', component:Error } 这里的path:’*’就是找不到页面时的配置,component是 ...

  6. Vue 实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案

    Vue实现动态路由及登录&404页面跳转控制&页面刷新空白解决方案   by:授客 QQ:1033553122   开发环境   Win 10   Vue 2.9.6   node-v ...

  7. 2种方式解决vue路由跳转未匹配相应路由避免出现空白页面或者指定404页面

    https://www.cnblogs.com/goloving/p/9254084.html https://www.cnblogs.com/goloving/p/9254084.html 1.路由 ...

  8. vue单页面打包文件大?首次加载慢?按需加载?是你打开方式不对

    部署各vue项目,走了一遍坑.... vue单页面应用刷新404 找到nginx多网站配置文件:类似nginx/sites-available/www.baidu.com server { liste ...

  9. thinkphp访问不存在的模块或者方法跳转到404页面

    使用的thinkphp 版本是3.2.0, 在config.php中配置 404地址,即可: 'TMPL_EXCEPTION_FILE' => './Application/Home/View/ ...

随机推荐

  1. linux下查看最后登陆的用户的信息

    [root@oracle ~]# last -aroot pts/1 Wed Apr 1 10:35 still logged in 10.3.12.1输入命令last -a 把从何处登入系统的主机名 ...

  2. 九章面试题:Find first K frequency numbers 解题报告

    Find first K frequency numbers /* * Input: int[] A = {1, 1, 2, 3, 4, 5, 2}; k = 3 * return the highe ...

  3. type、object和class的关系

  4. RedHat下安装Python开发环境

    Linux RedHat下安装Python2.7.pip.ipython环境.eclipse和PyDev环境 准备工作,源Python2.6备份: 根据which python具体目录而定,进行备份 ...

  5. mysql memory engine

    前言 刚刚遇到了mysql无法插入数据,报错:the table xxx is full. 查询原因,是xx表使用了memory engine,其中mysql的memory engine中有max_h ...

  6. Phrase-Based & Neural Unsupervised Machine Translation基于短语非监督机器翻译

    1. 前言 本文介绍一种无监督的机器翻译的模型.无监督机器翻译最早是<UNSUPERVISED NEURAL MACHINE TRANSLATION>提出.这个模型主要的特点,无需使用平行 ...

  7. Laravel 5.4 Cache::put的一个小坑

    使用的是Cache的file驱动,然而在\Cache::put($key,$value)时发现,并没有存入. 一开始以为是file驱动的问题,后来跟踪代码发现,居然源码里当过期时间不设置时,根本不保存 ...

  8. [转]我的MYSQL学习心得(六) 函数

    这一节主要介绍MYSQL里的函数,MYSQL里的函数很多,我这里主要介绍MYSQL里有而SQLSERVER没有的函数 数学函数 1.求余函数MOD(X,Y) MOD(X,Y)返回x被y除后的余数,MO ...

  9. C语言 · 字串逆序

    算法训练 字串逆序   时间限制:1.0s   内存限制:512.0MB      问题描述 给定一个字符串,将这个串的所有字母逆序后输出. 输入格式 输入包含一个字符串,长度不超过100,字符串中不 ...

  10. if语句和switch语句

    1.基本写法 if if(逻辑表达式){语句:}else if{语句:else{语句:} switch switch(变量){case 常量值:语句:break:default:语句:} 2.举例 i ...