【Vue3】发布为dist后,刷新路由页面出现404错误或Cannot GET /category错误(已解决)

试了N多方法没有解决,最后,在router的配置文件index.js中,把createWebHistory换成createWebHashHistory,解决了!

import {createRouter, createWebHistory,createWebHashHistory,useRouter} from 'vue-router'

const routes = [

    {
        path: '/',
        name: 'home',
        component: () => import('/src/view/Home.vue')
    },
    {
        path: '/home',
        name: 'home',
        component: () => import('/src/view/Home.vue')
    },
    
    {
        name: 'demo',
        path: '/demo',
        component: () => import('/src/view/Demo.vue')
    },
    {
        name: 'edit',
        path: '/edit:#:id:name',
        component: () => import('/src/view/TimeEdit.vue')
    },
    {
      path: '/:catchAll(.*)',
      name: 'not-found',
      component: () => import('/src/view/Home.vue')
    }
     
        
];

const router = createRouter({
    history: createWebHashHistory(), 
    // history: createWebHistory(), 
    routes
})

export default router

猜你喜欢

转载自blog.csdn.net/dxnn520/article/details/130777608