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

相关推荐
_OP_CHEN12 小时前
【前端开发之HTML】(四)HTML 标签进阶:表格、表单、布局全掌握,从新手到实战高手!
前端·javascript·css·html·html5·网页开发·html标签
南梦浅12 小时前
Flask+Gunicorn+Nginx 校园众筹项目部署全流程(生产环境)
nginx·flask·gunicorn
谢尔登12 小时前
Vue3底层原理——keep-alive
javascript·vue.js·ecmascript
Deca~12 小时前
VueVirtualLazyTree-支持懒加载的虚拟树
前端·javascript·vue.js
har01d12 小时前
AI生成的 vue3 日历组件,显示农历与节日,日期可选择,年月可切换
前端·vue.js·节日
我穿棉裤了12 小时前
文字换行自动添加换行符“-”
前端·javascript·vue.js
入门级前端开发13 小时前
vue集成xlsl实现前端表格导入导出
前端·javascript·vue.js
无知的小菜鸡13 小时前
React:使用高阶组件实现vue中的路由守卫功能
前端·vue.js·react.js
卿着飞翔14 小时前
win11安装配置nginx并部署ruoyi前端
运维·前端·nginx