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

相关推荐
Zhencode41 分钟前
Vue3响应式原理之ref篇
vue.js
小疙瘩2 小时前
element-ui 中 el-upload 多文件一次性上传的实现
javascript·vue.js·ui
独泪了无痕2 小时前
useStorage:本地数据持久化利器
前端·vue.js
呆子小木心4 小时前
Vue2或Vue3项目引用百度地图
javascript·vue.js·typescript·前端框架·html5
UI设计兰亭妙微6 小时前
资金运营管理监控系统交互设计、UI设计及VUE开发
vue.js·ui·交互
王子肥波6 小时前
🚀 TabTab Admin:一款现代化的 Vue 3 后台管理系统模板
vue.js
白开水丶7 小时前
vue3源码学习(五)ref 、toRef、toRefs、proxyRefs 源码学习
前端·vue.js·学习
不想秃头的程序员8 小时前
Vue3 子传父全解析:从基础用法到实战避坑
前端·vue.js·面试
简单Janeee9 小时前
[Vue 3 从零到上线]-第三篇:网页的指挥官——指令系统 (v-if, v-for, v-bind, v-on)
前端·javascript·vue.js
前端程序猿i9 小时前
第 7 篇:性能优化 —— 大量消息下的流畅体验
前端·vue.js·性能优化