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

相关推荐
从文处安5 小时前
「九九八十一难」组合式函数到底有什么用?
前端·vue.js
用户11489669441056 小时前
VUE3响应式原理——从零解析
vue.js
用户83040713057016 小时前
SPA 首屏加载速度慢怎么解决?
vue.js·webpack
一枚前端小姐姐6 小时前
低代码平台表单设计系统技术分析(实战三)
前端·vue.js·低代码
SuperEugene6 小时前
从 Vue2 到 Vue3:语法差异与迁移时最容易懵的点
前端·vue.js·面试
Leon7 小时前
新手引导 intro.js 的使用
前端·javascript·vue.js
Forever7_7 小时前
仅用一个技巧,让 JavaScript 性能提速 500%!
前端·vue.js
青屿ovo9 小时前
Vue前端页面版本检测解决方案
前端·vue.js
apollo_qwe11 小时前
深入解析Vue的mixins与hooks:复用逻辑的两种核心方式
vue.js
_AaronWong12 小时前
Vue3+Element Plus 通用表格组件封装与使用实践
前端·javascript·vue.js