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

相关推荐
用户8417948145629 分钟前
vxe-table 实现滚动加载数据,无限加载数据教程
vue.js
_请输入用户名43 分钟前
Vue 3 源码项目结构详解
前端·vue.js
前端无涯1 小时前
Vue3---(2)setup
vue.js
前端无涯1 小时前
Vue---scoped,deep,CSS Modules
vue.js
前端无涯1 小时前
Vue3---(1)项目工程创建
vue.js
前端无涯1 小时前
Vue3---(3)ref,reactive,toRefs,toRef
vue.js
哆啦A梦15881 小时前
商城后台管理系统 01 Vue-i18n国际化
前端·javascript·vue.js
期待のcode1 小时前
Vue的安装创建与运行
前端·javascript·vue.js
+VX:Fegn08951 小时前
计算机毕业设计|基于springboot + vue旅游信息推荐系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计·旅游
码界奇点1 小时前
基于SpringBoot和Vue的Fuint门店会员营销系统设计与实现
vue.js·spring boot·后端·毕业设计·springboot·源代码管理