vue3+vue-router4 路由HTML5模式(createWebHistory ),编译后部署到nginx,点击路由跳转正常,但是刷新页面报404

javascript 复制代码
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    {
      path: '/index/home',
      component: () => import('../views/index/Home.vue'),
    },
    {
      path: '/home',
      component: () => import('../views/home/Index.vue'),
    },
    {
      path: '/me',
      component: () => import('../views/me/Index.vue'),
    },
  ],
})

router.beforeEach((to, from) => {
  return true
})

export default router

不兼容:

bash 复制代码
    server {
        listen 80;
        server_name localhost chat.test.com;

        #配置根目录
        location / {
            root    /temp/test;
            index  index.html index.htm;
            add_header Content-Security-Policy upgrade-insecure-requests;
        }
    }  

解决方案:

bash 复制代码
    server {
        listen 80;
        server_name localhost chat.test.com;

        #配置根目录
        location / {
            root    /temp/test;
            #index  index.html index.htm;
            try_files $uri $uri/ /index.html;
            add_header Content-Security-Policy upgrade-insecure-requests;
        }
    }  

参考链接

https://router.vuejs.org/zh/guide/essentials/history-mode.html#nginx

人工智能学习网站

https://chat.xutongbao.top

相关推荐
Csvn6 小时前
Nginx 性能调优与压测:连接账本、找拐点与调优前后对比
后端·nginx
夏与冰14 小时前
Vue2项目中数据字典的使用封装
前端·javascript·vue.js·elementui
tryCbest16 小时前
Vue系列——第 24 篇:VueUse——组合式工具集的百宝箱
前端·vue.js
沐言人生1 天前
自媒体人的效率神器!监控、采集、下载、发布,这个免费开源工具全拿下!
前端·vue.js·后端
Csvn1 天前
Nginx 与 OpenResty:阶段钩子、shared dict 与动态 upstream/证书
后端·nginx
DKPT1 天前
AI广场 · 从零到上线完整部署教程
vue.js
洋洋技术笔记1 天前
过渡与动画效果
vue.js
小小小小宇2 天前
浏览器自动化实战:把「打开掘金写一篇文章」变成可复用的 Skill
vue.js·自动化运维
Iseeyore2 天前
Vue3 Vs React
前端·vue.js
1-1=02 天前
Vue 混入(Mixin)和 2.插件 (Plugins)
前端·vue.js