|
|
@@ -1,5 +1,5 @@
|
|
|
import React, { createContext, useContext, useState, ReactNode, useEffect } from 'react';
|
|
|
-
|
|
|
+const VITE_BASE_PATH = import.meta.env.VITE_BASE_PATH
|
|
|
type PageType = 'home' | 'about' | 'blog' | 'careers' | 'privacy' | 'terms' | 'faq' | 'contact';
|
|
|
|
|
|
interface RouterContextType {
|
|
|
@@ -61,10 +61,20 @@ function scrollToElement(elementId: string, initialDelay: number = 150) {
|
|
|
}, initialDelay);
|
|
|
}
|
|
|
|
|
|
+function extractPath(url: string): string | null {
|
|
|
+ const prefix = VITE_BASE_PATH;
|
|
|
+ if (url.startsWith(prefix)) {
|
|
|
+ return url.slice(prefix.length);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
export function RouterProvider({ children }: { children: ReactNode }) {
|
|
|
// Initialize page based on current URL path
|
|
|
const getInitialPage = (): PageType => {
|
|
|
- const path = window.location.pathname;
|
|
|
+ const result = extractPath(window.location.pathname);
|
|
|
+ const path = result ?? '';
|
|
|
+ console.log(path)
|
|
|
return pathToPage[path] || 'home';
|
|
|
};
|
|
|
|
|
|
@@ -73,21 +83,21 @@ export function RouterProvider({ children }: { children: ReactNode }) {
|
|
|
// Handle initial page load
|
|
|
useEffect(() => {
|
|
|
const pathname = window.location.pathname;
|
|
|
-
|
|
|
// Ensure pathname is normalized
|
|
|
if (pathname === '' || pathname === null) {
|
|
|
window.history.replaceState({ page: 'home' }, '', '/');
|
|
|
+ }else{
|
|
|
+
|
|
|
}
|
|
|
}, []);
|
|
|
|
|
|
const navigateTo = (page: PageType, hash?: string) => {
|
|
|
setCurrentPage(page);
|
|
|
-
|
|
|
const path = pageToPath[page];
|
|
|
const url = hash ? `${path}#${hash}` : path;
|
|
|
-
|
|
|
+ const BASE_PATH = VITE_BASE_PATH
|
|
|
// Update browser URL without reloading
|
|
|
- window.history.pushState({ page }, '', url);
|
|
|
+ window.history.pushState({ page }, '', BASE_PATH + url);
|
|
|
|
|
|
if (hash) {
|
|
|
// If there's a hash, scroll to the section
|
|
|
@@ -103,7 +113,6 @@ export function RouterProvider({ children }: { children: ReactNode }) {
|
|
|
const path = window.location.pathname;
|
|
|
const page = pathToPage[path] || 'home';
|
|
|
setCurrentPage(page);
|
|
|
-
|
|
|
// Handle hash if present
|
|
|
const hash = window.location.hash.replace('#', '');
|
|
|
if (hash) {
|