Skip to content

Commit

Permalink
fix: implement hash-based routing for GitHub Pages
Browse files Browse the repository at this point in the history
- Replace memory history with hash history to handle direct URL navigation
- Prevents 404 errors when accessing routes directly
- URLs will now use hash-based format (e.g., /#/about)
- https://tanstack.com/router/v1/docs/framework/react/guide/history-types#hash-routing
- https://stackoverflow.com/questions/77466065/using-tanstack-router-with-a-spa-in-github-pages
  • Loading branch information
ligsnf committed Dec 23, 2024
1 parent f738cf0 commit 8fe9253
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { StrictMode } from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import { RouterProvider, createRouter } from '@tanstack/react-router'
import { RouterProvider, createRouter, createHashHistory } from '@tanstack/react-router'
import { ThemeProvider } from "@/components/theme/theme-provider"

// Import the generated route tree
import { routeTree } from './routeTree.gen'

// Create a hash history
const hashHistory = createHashHistory()

// Create a new router instance
const router = createRouter({
routeTree,
basepath: "/monash-grades-calculator/",
history: hashHistory,
})

// Register the router instance for type safety
Expand Down

0 comments on commit 8fe9253

Please sign in to comment.