gpt4 book ai didi

javascript - Netlify 和 React Vite : Netlify says "Page not found" upon reloading in Vite and React site

转载 作者:行者123 更新时间:2023-12-03 07:58:14 25 4
gpt4 key购买 nike

我有一个用 React JS 构建的网站,我使用 Vite 作为 JS Bundler。问题是,当我在 Netlify 上部署网站并重新加载页面时,它显示“找不到页面”。

我尝试添加更改 vite.config.js 文件。

import { defineConfig } from "vite";
import { resolve } from "path";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
},
},
},
plugins: [react()],
});

我还添加了 .redirects 文件。

请为此提供一个解决方案,我认为这是一个常见问题,但尚未得到太多解决。

最佳答案

I see this as a common issue but it hasn't been addressed much.

解决这个问题只能通过文档来解决,不幸的是,如果不引用文档,也无济于事。

没有看到您的网站以及对此常见问题的描述,我只能“假设”您正在谈论刷新时出现 404 问题,就像昨天发布的另一个类似问题一样:Routes not working properly in React using Vite (ON BUILD)

该解决方案记录在 React 文档中(好吧,创建 React App,但在这种情况下也有效):https://create-react-app.dev/docs/deployment/#netlify

您需要创建一个文件 public/_redirects ,其内容为:

/* /index.html 200

您已经提到您已经这样做了,但除非它遵循上面的确切位置和语法,否则它将无法工作。

关于javascript - Netlify 和 React Vite : Netlify says "Page not found" upon reloading in Vite and React site,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75386783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com