router - 虽然我不能在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 中获取当前路由的最佳方法是什么?
解决方案
推荐阅读
- java - 每个缓存的 Redis 大小限制
- html - 如何在不裁剪或换行的情况下限制列宽?
- python - 将晶石矩阵转换为具有列名的数组时出现内存错误。该数组输入到训练模型
- c# - CSharpFits:写入 FITS 文件会导致图像错误
- xslt - 你如何测试一个值是否与一组值中的一个匹配?
- python - 在子图直方图上绘制范数曲线
- c# - 如何使文本显示所有 8 位数字并在此之后清除文本?
- numpy - 将 numpy 数组作为 jpeg 写入缓冲区
- javascript - Web-Worker 导入的脚本可以依次导入另一个脚本吗?
- java - 如何将java库连接到项目以测试库