fix in app.jsx for the routes depending on whether it is in the browser (BrowserRouter) or if it is in electron (HashRouter) so that there are no problems in the routes

This commit is contained in:
DNLRQ 2024-11-30 18:51:39 -07:00
parent 1b56da8c36
commit 18a98e3ecb
3 changed files with 60 additions and 3 deletions

26
package-lock.json generated
View File

@ -20,6 +20,7 @@
"classnames": "^2.5.1", "classnames": "^2.5.1",
"dexie": "^3.2.4", "dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.7", "dexie-react-hooks": "^1.1.7",
"electron-is": "^3.0.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"framer-motion": "^10.18.0", "framer-motion": "^10.18.0",
"html-to-image": "^1.11.11", "html-to-image": "^1.11.11",
@ -5368,6 +5369,31 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/electron-is": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/electron-is/-/electron-is-3.0.0.tgz",
"integrity": "sha512-aQv1y3WrDZ+mtO8acbhiiip/8fa0Et7cvZyvlqJm2H7fih4hiJWEFRyYxzLgDG2kmiLdF8l3y5tbek5JFOPQkQ==",
"license": "MIT",
"dependencies": {
"electron-is-dev": "^0.3.0",
"semver": "^5.5.0"
}
},
"node_modules/electron-is-dev": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-0.3.0.tgz",
"integrity": "sha512-jLttuuq8QK67n3mXmIe9pkrO7IH3LGIk12xJkhTmc852U2sCJaRAOpRGPSh+1Xnzck5v9escd9YXzuze9nGejg==",
"license": "MIT"
},
"node_modules/electron-is/node_modules/semver": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz",
"integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==",
"license": "ISC",
"bin": {
"semver": "bin/semver"
}
},
"node_modules/electron-publish": { "node_modules/electron-publish": {
"version": "25.1.7", "version": "25.1.7",
"resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-25.1.7.tgz", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-25.1.7.tgz",

View File

@ -26,6 +26,7 @@
"classnames": "^2.5.1", "classnames": "^2.5.1",
"dexie": "^3.2.4", "dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.7", "dexie-react-hooks": "^1.1.7",
"electron-is": "^3.0.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"framer-motion": "^10.18.0", "framer-motion": "^10.18.0",
"html-to-image": "^1.11.11", "html-to-image": "^1.11.11",

View File

@ -1,4 +1,4 @@
import { HashRouter, Routes, Route, useLocation } from "react-router-dom"; import { BrowserRouter, HashRouter, Routes, Route, useLocation } from "react-router-dom";
import { useLayoutEffect } from "react"; import { useLayoutEffect } from "react";
import Editor from "./pages/Editor"; import Editor from "./pages/Editor";
import Survey from "./pages/Survey"; import Survey from "./pages/Survey";
@ -10,10 +10,40 @@ import SettingsContextProvider from "./context/SettingsContext";
import { useSettings } from "./hooks"; import { useSettings } from "./hooks";
import NotFound from "./pages/NotFound"; import NotFound from "./pages/NotFound";
function isElectron() {
if (
typeof window !== "undefined" &&
typeof window.process === "object" &&
window.process.type === "renderer"
) {
return true;
}
if (
typeof process !== "undefined" &&
typeof process.versions === "object" &&
!!process.versions.electron
) {
return true;
}
if (
typeof navigator === "object" &&
typeof navigator.userAgent === "string" &&
navigator.userAgent.indexOf("Electron") >= 0
) {
return true;
}
return false;
}
const Router = isElectron() ? HashRouter : BrowserRouter;
export default function App() { export default function App() {
return ( return (
<SettingsContextProvider> <SettingsContextProvider>
<HashRouter> <Router>
<RestoreScroll /> <RestoreScroll />
<Routes> <Routes>
<Route path="/" element={<LandingPage />} /> <Route path="/" element={<LandingPage />} />
@ -52,7 +82,7 @@ export default function App() {
<Route path="/templates" element={<Templates />} /> <Route path="/templates" element={<Templates />} />
<Route path="*" element={<NotFound />} /> <Route path="*" element={<NotFound />} />
</Routes> </Routes>
</HashRouter> </Router>
</SettingsContextProvider> </SettingsContextProvider>
); );
} }