问题描述:
在 Vercel 上部署项目后,我遇到了页面之间导航的问题。该项目在本地运行得很好,我可以毫无问题地在页面之间导航。但是,部署到 Vercel 后,某些页面在导航时无法加载或导致 404 错误。
项目链接:
GitHub 存储库
https://github.com/FadyFathey/digitalize-v.2.git
Vercel 部署:
https://digitalize-v-2.vercel.app/
项目结构:
DIGITALIZE-V.2
├── AboutUs
│ └── html
│ └── digitalize
│ ├── assets
│ └── about.html
├── blogs
│ └── html
│ └── digitalize
│ ├── assets
│ └── blogs.html
├── blogs-details
│ └── html
│ └── digitalize
│ ├── assets
│ └── blog-details.html
├── contact us
│ └── html
│ └── digitalize
│ ├── assets
│ └── contact.html
├── ourServices
│ └── html
│ └── digitalize
│ ├── assets
│ └── service.html
└── vercel.json
当前 vercel.json 配置:
{
"version": 2,
"rewrites": [
{
"source": "/about",
"destination": "/AboutUs/html/digitalize/about.html"
},
{
"source": "/contact",
"destination": "/contact us/html/digitalize/contact.html"
},
{
"source": "/ourServices",
"destination": "/ourServices/html/digitalize/service.html"
},
{
"source": "/blogs",
"destination": "/blogs/html/digitalize/blogs.html"
},
{
"source": "/blog-details",
"destination": "/blogs-details/html/digitalize/blog-details.html"
},
{
"source": "/(.*)",
"destination": "/html/digitalize/index.html"
}
],
"cleanUrls": true,
"trailingSlash": false
}
到目前为止我尝试过的:
修改了 vercel.json:我尝试了不同的重写配置,但页面之间的导航仍然无法按预期工作。 验证文件夹结构:我确认 Vercel 上的文件夹结构与本地结构完全匹配。 测试链接:链接在本地工作,但部署后,Vercel 无法识别某些页面。
问题:
如何配置 vercel.json 以确保部署后页面之间的导航正常工作?我是否缺少特定的重写配置来解决此导航问题?
从未对文件夹结构中的文件进行过多次重写,但可能值得尝试以下操作。
"rewrites": [{ "source": "/about", "destination": "AboutUs/html/digitalize/about.html" }]
"rewrites": [{ "source": "/contact", "destination": "contact us/html/digitalize/contact.html" }]
"rewrites": [{ "source": "/ourServices", "destination": "ourServices/html/digitalize/service.html" }]
"rewrites": [{ "source": "/blogs", "destination": "blogs/html/digitalize/blogs.html" }]
"rewrites": [{ "source": "/blog-details", "destination": "blogs-details/html/digitalize/blog-details.html" }]
"rewrites": [{ "source": "/(.*)", "destination": "html/digitalize/index.html" }]