search
HomeWeb Front-endFront-end Q&AWhat to do if vue package refresh error is reported

Solution to vue package refresh error: 1. Change the "mode" of vue router to "hash"; 2. Modify Nginx to "location / {root ...index ...try_files $uri $ uri/ /index.html;}"; 3. Modify Apache to "RewriteRule . /index.html [L]" and save it.

What to do if vue package refresh error is reported

#The operating environment of this tutorial: Windows 10 system, Vue version 3, Dell G3 computer.

What should I do if vue packages and refreshes an error?

Vue project refreshes and reports 404 after deployment. Solution

1. Reason

Due to the use of vue router mode in the project built by vue before The default mode hash, the 404 will not appear when refreshing the page after the project is packaged and deployed.

However, due to project requirements, the mode of vue router was changed to history. As a result, there was no problem in jumping to the page. When refreshing the page, it reported 404 error

2. Solution:

Option 1: Change the mode of vue router to hash

Option 2: nginx modification

location / {
  root ...
  index ...
  try_files $uri $uri/ /index.html; ---解决页面刷新404问题
} 

As shown:

What to do if vue package refresh error is reported

Warning:

Because after doing this, your server will no longer return a 404 error page, because the index.html file will be returned for all paths. To avoid this, you should cover all routing situations in your Vue application and then present a 404 page. Or, if you are using Node.js as the backend, you can use server-side routing to match the URL, and return 404 when no route is matched, thereby implementing fallback.

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '*', component: NotFoundComponent }
  ]
})

Option 3: 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>

Recommended learning: "vue.js Video Tutorial"

The above is the detailed content of What to do if vue package refresh error is reported. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
分享PyCharm项目打包的简易方法分享PyCharm项目打包的简易方法Dec 30, 2023 am 09:34 AM

简单易懂的PyCharm项目打包方法分享随着Python的流行,越来越多的开发者使用PyCharm作为Python开发的主要工具。PyCharm是功能强大的集成开发环境,它提供了许多方便的功能来帮助我们提高开发效率。其中一个重要的功能就是项目的打包。本文将介绍如何在PyCharm中简单易懂地打包项目,并提供具体的代码示例。为什么要打包项目?在Python开发

如何使用Python正则表达式进行代码打包和分发如何使用Python正则表达式进行代码打包和分发Jun 23, 2023 am 09:31 AM

随着Python编程语言的日益流行,越来越多的开发者开始使用Python编写代码。但是在实际使用中,我们常常需要将这些代码打包并分发给其他人使用。本文将介绍如何使用Python正则表达式进行代码打包和分发。一、Python代码打包在Python中,我们可以使用setuptools和distutils等工具来打包我们的代码。这些工具可以将Python文件、模块

怎么使用pkg将Node.js项目打包为可执行文件?怎么使用pkg将Node.js项目打包为可执行文件?Jul 26, 2022 pm 07:33 PM

如何用pkg打包nodejs可执行文件?下面本篇文章给大家介绍一下使用pkg将Node.js项目打包为可执行文件的方法,希望对大家有所帮助!

linux打包是什么意思linux打包是什么意思Feb 23, 2023 pm 06:30 PM

在linux中,打包指的是一个文件或目录的集合,而这个集合被存储在一个文件中;简单来说,打包是指将一大堆文件或目录变成一个总的文件。打包文件没有经过压缩,因此它占用的空间是其中所有文件和目录的总和。

Python 应用的终极进化:PyInstaller 的破茧成蝶Python 应用的终极进化:PyInstaller 的破茧成蝶Feb 19, 2024 pm 03:27 PM

PyInstaller是一个革命性的工具,它赋予python应用程序以超越其原始脚本形态的能力。通过将Python代码编译成独立的可执行文件,PyInstaller解锁了代码分发、部署和维护的新境界。从单一脚本到强大应用程序以往,Python脚本只存在于特定的Python环境中。分发这样的脚本需要用户安装Python和必要的库,这是一个费时且繁琐的过程。PyInstaller引入了打包的概念,将Python代码与所有必需的依赖项组合成一个单独的可执行文件。代码打包的艺术PyInstaller的工

Python 应用的独立宣言:PyInstaller 的自由之路Python 应用的独立宣言:PyInstaller 的自由之路Feb 20, 2024 am 09:27 AM

PyInstaller:Python应用的独立化PyInstaller是一款开源的python打包工具,它将Python应用程序及其依赖项打包为一个独立的可执行文件。这一过程消除了对Python解释器的依赖,同时允许应用程序在各种平台上运行,包括windows、MacOS和linux。打包过程PyInstaller的打包过程相对简单,涉及以下步骤:pipinstallpyinstallerpyinstaller--onefile--windowedmain.py--onefile选项创建一个单一

PyCharm教程:如何将Python代码打包成EXE文件PyCharm教程:如何将Python代码打包成EXE文件Feb 21, 2024 pm 12:12 PM

在本文中,我们将介绍PyCharm中的一种常用方法,通过使用PyInstaller将Python代码打包成可执行的EXE文件。PyInstaller是一个用于将Python应用程序转换为独立的可执行文件的工具,它可以将Python代码打包成EXE、APP、Linux等格式,方便用户在没有安装Python解释器的环境中运行Python程序。步骤一:安装PyIn

如何正确理解 Linux 中打包和压缩的不同之处如何正确理解 Linux 中打包和压缩的不同之处Feb 20, 2024 pm 05:33 PM

Linux中打包和压缩是经常用到的操作,但许多用户往往混淆这两者的概念。本文将详细讨论在Linux系统中打包和压缩的不同之处,并通过具体的代码示例来帮助读者更好地理解。首先,需要明确打包和压缩的区别。打包是将多个文件或目录组合成一个单独的文件,通常用于整理、归档或传输文件。而压缩是将一个或多个文件通过算法进行压缩,以减小文件的大小,节省存储空间或加快传输速

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment