Pad*_*r08 7 vue.js vue-router netlify vercel vite
我正在使用 vite 制作一个项目,该项目使用 vue-router@4。它工作得很好,但是当查看 vercel 或 netlify 上的链接时,我收到 404 错误。这是我的 index.js 文件(路由器设置)
import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import Admin from "../views/Admin.vue";
import List from "../views/List.vue";
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: "/",
component: Home,
},
{
path: "/adminpanel",
component: Admin,
},
{
path: "/list",
component: List
}
],
});
export default router;
Run Code Online (Sandbox Code Playgroud)
我做错了什么吗?感谢您的帮助。
小智 34
Add a rewrites configuration to allow you to send users to different URLs without modifying the visible URL.
Create a file called
vercel.json
Run Code Online (Sandbox Code Playgroud)
at the root folder
then add
{
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}
Run Code Online (Sandbox Code Playgroud)
Source: https://vercel.com/docs/configuration#project/rewrites