使用vite打包vue项目生成dist文件夹,部署至nginx除了index.html,其他路径都提示404错误的解决

hykeda2年前Vue2984

vue打包生成dist文件夹,然后在本地nginx部署vue项目时只能访问默认页面,刷新和跳转页面都会出问题。

f341a9addb164e22aee5e4d91dae2cca.png

原因:

只访问了dist文件下的 index.html、index.htm页面,而其他页面在访问的时候被nginx当作自身的服务访问而找不到,我们修改一下配置文件。


方法:

添加上 try_files $uri $uri/ /index.html;

location / {
        try_files $uri $uri/ /index.html; # 用于支持Vue-router的history模式
    }


相关文章

vue3中defineProps传值使用ref响应式失效详解

子组件接收父组件的传参。父组件:<template> <Son :data="data"/> </template> <s...

vue3项目,Element-plus ElMessage API 调用样式丢失问题

1、Element-plus使用了自动按需导入,vite.config.js配置如下:defineConfig({     plugins: [...

vite+vue 插件/组件集合

自动引入插件:https://github.com/antfu/unplugin-auto-importvue的按需组件自动导入:https://github.com/antfu/unplugin-v...

学习lodash

官网:https://www.lodashjs.com/ 链接:https://www.jianshu.com/p/d46abfa4ddc9 简介 L...

vite.config.js配置@

import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'import path f...

Vue2.x笔记

vue2.0 开始不能挂载到<html> 或者 <body> 上。 transition 动画过渡的时候,如果是:<transit...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。