admin管理员组文章数量:1278721
I have the site built in React JS where I am using Vite as a JS Bundler. The problem is, when I deployed the site on Netlify and when reloading the page it says "Page not found".
I tried adding changing vite.config.js
file.
import { defineConfig } from "vite";
import { resolve } from "path";
import react from "@vitejs/plugin-react";
// /config/
export default defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
},
},
},
plugins: [react()],
});
I also added .redirects file.
Please provide a solution for this, I see this as a mon issue but it hasn't been addressed much.
I have the site built in React JS where I am using Vite as a JS Bundler. The problem is, when I deployed the site on Netlify and when reloading the page it says "Page not found".
I tried adding changing vite.config.js
file.
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()],
});
I also added .redirects file.
Please provide a solution for this, I see this as a mon issue but it hasn't been addressed much.
Share Improve this question asked Feb 8, 2023 at 13:52 Ali Ahmed KhanAli Ahmed Khan 1582 silver badges7 bronze badges2 Answers
Reset to default 11I see this as a mon issue but it hasn't been addressed much.
Addressing this issue can only happen through documentation, which unfortunately if not referred to, cannot be helped.
Without seeing your site and the description of this being a mon issue, I can only "assume" you're talking about the 404 on refresh problem, just like the another similar question posted about yesterday: Routes not working properly in React using Vite (ON BUILD)
The solution is documented on React docs (well, Create React App, but valid in this case too): https://create-react-app.dev/docs/deployment/#netlify
You need to create a file, public/_redirects
with the content:
/* /index.html 200
You already mention you've done that, but unless it follows the exact placement and syntax as above, it won't work.
For Netlify
To set up a _redirects file in your public folder, follow these steps. Assuming you're using React with Vite:
Navigate to your project's public folder.
Create a new file named _redirects.
Paste the following code into the _redirects file:
/* /index.html 200
For Vercel
Create a file named vercel.json in the root folder of your project.
{
"rewrites": [
{
"source": "/(.*)",
"destination": "/"
}
]
}
Same issue: Click Here
本文标签:
版权声明:本文标题:javascript - Netlify and React Vite: Netlify says "Page not found" upon reloading in Vite and React site - Sta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741256278a2366734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论