首页 > 解决方案 > 虽然我不能在vue3中使用publicPath,但我在路由器上得到404

问题描述

我正在其他地方发布我的 vue3 项目。
例如https://vue3project.test.com/appointment/ 我把我的项目扔进去了

我的公共道路;

module.exports = {
    // options...
    //publicPath: "/",
    publicPath: process.env.NODE_ENV === "production" ? "/appointment/" : "/",
};

和我的路由器;

import { createRouter, createWebHistory } from "vue-router";

import MainScreen from "../components/MainScreen.vue";
import AppointmentCancel from "../components/AppointmentCancel.vue";

const routes = [
    {
        path: "/",
        name: "MainScreen",
        component: MainScreen,
    },
    {
        path: "/cancel",
        name: "AppointmentCancel",
        component: AppointmentCancel,
    }

];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes,
});

export default router;

我在切换baseurl/appointment/cancel时收到 404 错误,我该如何解决这个问题?在添加 publicPath 和设置 publicPath 之后,我在 /appointment 中得到它,这修复了它。但是现在我为路由器设置的路径遇到了这个问题。

我尝试过;
使用 vue3 路由重新加载页面时出现错误 404
在 Vue3 和 Vue-router 中获取当前路由的最佳方法是什么?

标签: routervuejs3

解决方案


推荐阅读