最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to resolve 404 error in a deployed react- vite app? - Stack Overflow

programmeradmin0浏览0评论

I have a production-ready React app built with vite. I have run the build process and uploaded the contents of the dist file within the subdirectory it is supposed to be in. When i visit the URL it throws a 404 error in the console. Failed to load resource: the server responded with a status of 404 (Not Found) - index-77febc61.js:1 for my index.js file. I have checked the index.html file to ensure the src tag is pointing to the right js file and it seems fine.

The URL to the site should be . All the files are uploaded in the subscriber directory but on visiting the site it shows a white screen with the 404 error.

Any help on how i could resolve this is greatly appreciated.

I have a production-ready React app built with vite. I have run the build process and uploaded the contents of the dist file within the subdirectory it is supposed to be in. When i visit the URL it throws a 404 error in the console. Failed to load resource: the server responded with a status of 404 (Not Found) - index-77febc61.js:1 for my index.js file. I have checked the index.html file to ensure the src tag is pointing to the right js file and it seems fine.

The URL to the site should be https://mydomainname./susbcriber. All the files are uploaded in the subscriber directory but on visiting the site it shows a white screen with the 404 error.

Any help on how i could resolve this is greatly appreciated.

Share Improve this question asked Sep 6, 2023 at 14:56 NateNate 951 gold badge3 silver badges12 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You should create a vercel.json file in the root directory and put this code inside it

    {
    "routes":[
        {
            "src":"/[^.]+",
            "dest":"/"
        }
    ]
    }

I guarantee it will work

There are some solutions, for me was the .htaccess

I put this in my .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

And this in my vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  base: '/',
})

I Had The Same in react vite issue I resolve this by using:

import React from "react";

Use this in every ponent you are using and then deploy it again

发布评论

评论列表(0)

  1. 暂无评论