Skip to content

Commit

Permalink
fixing electron routes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmcclew committed Feb 19, 2024
1 parent 5ba1e32 commit 0cb5a51
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
10 changes: 4 additions & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import { Route } from "react-router-dom";
import HomePage from './pages/HomePage';
import RoutingComponent from './components/RoutingComponent';
import AboutPage from './pages/AboutPage';
import MainPage from './pages/MainPage';
import PersuasivePage from './pages/PersuasivePage';
Expand All @@ -9,17 +10,14 @@ import ReviewsPage from './pages/ReviewsPage';

function App() {
return (
<Router>
<Routes>
<RoutingComponent>
<Route path="/" element={<HomePage />} />
<Route path="/main" element={<MainPage />} />
<Route path="/about" element={<AboutPage />} />
<Route path="/persuasive" element={<PersuasivePage />} />
<Route path="/contact" element={<ContactPage />} />
<Route path="/reviews" element={<ReviewsPage />} />
</Routes>
</Router>

</RoutingComponent>
);
}

Expand Down
30 changes: 30 additions & 0 deletions frontend/src/components/RoutingComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { ReactNode } from 'react';
import { BrowserRouter as BrowserRouterImpl, HashRouter as HashRouterImpl, Routes } from 'react-router-dom';

interface RoutingComponentProps {
children: ReactNode;
}

const RoutingComponent: React.FC<RoutingComponentProps> = ({ children }) => {
if (isElectron()) {
return (
<HashRouterImpl>
<Routes>{children}</Routes>
</HashRouterImpl>
);
} else {
return (
<BrowserRouterImpl>
<Routes>{children}</Routes>
</BrowserRouterImpl>
);
}
}

function isElectron() {
// Check if running in Electron environment
const isElectron = navigator.userAgent.toLowerCase().indexOf(' electron/') > -1;
return isElectron;
}

export default RoutingComponent;

0 comments on commit 0cb5a51

Please sign in to comment.