React Router Breaks When Deployed To Firebase Hosting

I created a React Vite Js project a few weeks ago utilizing React Router with BrowserRouter and it was working fine. When I went to deploy some changes today, nothing of which messes with react router, the routing system broke. I shouldn’t say broke but it is super finicky. The base path loads with no problem. When the route is switched it is a toss up of what issue follows. It either gets re-routed back to the base path, like a refresh, or a firebase error pop up saying this path doesn’t exist.

I switched to HashRouter today in an attempt to solve this issue and stopped getting the Firebase error pop up, but am still getting instances where the route does not load but instead refreshes the base path.

To deploy the project, I first run npm run build and then firebase deploy.

When setting up hosting, I used firebase init chose hosting, set dist as my public directory, and set it up as a single page app (reroute all urls to /index.html).

Following I will put some of the code from the project:

Routing:

<HashRouter>
    <Sidebar openSidebarToggle={openSidebarToggle} OpenSidebar={OpenSidebar}/>
    <Header OpenSidebar={OpenSidebar}/>
    <Routes>
        <Route path='/' element={<Home/>} />
        <Route path='/messaging' element={<Messaging/>} />
        <Route path='/commands' element={<Commands/>} />
        <Route path='/genus' element={<Genus/>} />
        <Route path='/about' element={<AboutThisProject/>} />
        <Route path='/feedback' element={<Feedback/>} />
    </Routes>
</HashRouter>

Link To Open Route (Same for all routes but with different path)

<Link to='/messaging' style={{ textDecoration: 'none' }} onClick={{OpenSidebar}}>
    <li className='sidebar-list-item'>
        <a href="">
        <MdOutlineMessage className='icon'/> Messaging
        </a>
    </li>
</Link>

Firebase.json

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

vite.config.js

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  build: {
    chunkSizeWarningLimit: 1600,
  },
})

The project is still being hosted, so if you want to see the error in action, the link is https://sasquatch-dashboard-34157.web.app/

Recreate
To recreate the issue, go to the link above, which is the web app, and then click an option in the sidebar.

The codebase can be found at https://github.com/Logan-Rising/DiscordBotDashboard-WebApp

If you have any questions or need clarification, please let me know.

New contributor

Logan Rising is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật