Skip to content

Commit

Permalink
Fallback to route /
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Jul 12, 2023
1 parent 234b929 commit 3bcff0d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
4 changes: 2 additions & 2 deletions lexicon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@urbit/http-api": "^2.3.0",
"react-router-dom": "^6.4.3",
"react-router-dom": "^6.14.1",
"zustand": "^4.3.8"
},
"peerDependencies": {
Expand All @@ -31,4 +31,4 @@
"babel-loader": "^8.3.0",
"babel-plugin-styled-components": "^2.0.7"
}
}
}
65 changes: 34 additions & 31 deletions lexicon/src/Lexicon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { BrowserRouter, redirect, Route, Routes } from 'react-router-dom';
import { createGlobalStyle } from 'styled-components';

import {
Expand Down Expand Up @@ -28,6 +28,7 @@ const GlobalStyle = createGlobalStyle`
outline: none;
}
`;

declare global {
interface Window {
ship: string;
Expand Down Expand Up @@ -296,37 +297,39 @@ export const Lexicon = ({
useEffect(() => {
setShipName(shipName);
}, [shipName]);

useEffect(() => {
// Start at the root path.
redirect('/');
}, []);

if (!api) return null;

return (
<>
<main
style={{
overflowY: 'auto',
height: '100vh',
backgroundColor: 'transparent',
}}
>
<GlobalStyle />
<Router>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route
path="/index.html/:ship/:group/:word"
element={<WordPage />}
/>
<Route path="/index.html/:ship/:group" element={<HomePage />} />
<Route
path="/index.html/dict/:word"
element={<DictionaryPage />}
/>
<Route
path="/index.html"
element={<p>don't mind me just redirecting over here</p>}
/>
</Route>
</Routes>
</Router>
</main>
</>
<main
style={{
overflowY: 'auto',
height: '100vh',
backgroundColor: 'transparent',
}}
>
<GlobalStyle />
<BrowserRouter>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route
path="index.html/:ship/:group/:word"
element={<WordPage />}
/>
<Route path="index.html/:ship/:group" element={<HomePage />} />
<Route path="index.html/dict/:word" element={<DictionaryPage />} />
<Route
path="index.html"
element={<p>don't mind me just redirecting over here</p>}
/>
</Route>
</Routes>
</BrowserRouter>
</main>
);
};
2 changes: 1 addition & 1 deletion trove/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mime": "^3.0.0",
"moment": "^2.29.4",
"react-dnd-html5-backend": "^16.0.1",
"react-router-dom": "^6.4.3",
"react-router-dom": "^6.14.1",
"styled-components": "^5.3.6",
"styled-system": "^5.1.5",
"urbit-ob": "^5.0.1",
Expand Down
15 changes: 10 additions & 5 deletions trove/src/Trove.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { BrowserRouter, redirect, Route, Routes } from 'react-router-dom';
import { createTheme, ThemeProvider } from '@mui/material/styles';

import { trovePreload } from '../../app/src/os/services/ship/trove.service';
Expand Down Expand Up @@ -53,6 +53,11 @@ export const Trove = ({
const space = useTroveStore((store: TroveStore) => store.space);
const setApi = useTroveStore((store: TroveStore) => store.setApi);

useEffect(() => {
// Start at the root path.
redirect('/');
}, []);

useEffect(() => {
//subscribe to updates here
TroveIPC.UIUpdates();
Expand Down Expand Up @@ -90,11 +95,11 @@ export const Trove = ({
}}
>
<ThemeProvider theme={muiTheme}>
<Router>
<BrowserRouter>
<Routes>
<Route element={<Navigation selectedSpace={selectedSpace} />}>
<Route
path="index.html/:ship/:group"
path="/:ship/:group"
element={
<Home
useStorage={useStorage}
Expand All @@ -104,14 +109,14 @@ export const Trove = ({
}
/>
<Route
path="index.html/"
path="/"
element={
<>Enter a space in the url example: ...apps/trove/~zod/our</>
}
/>
</Route>
</Routes>
</Router>
</BrowserRouter>
</ThemeProvider>
</main>
);
Expand Down
1 change: 1 addition & 0 deletions trove/src/components/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WrappedBackground } from '../components';
import { splitLastOccurrence } from '../helpers';
import useTroveStore, { TroveStore } from '../store/troveStore';
import { theme } from '../theme';

export const NavigationHeader = () => {
const currentSpace = useTroveStore((store: TroveStore) => store.currentSpace);
const [stlfDisplay, setStflDisplay] = useState<string>('');
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17274,7 +17274,7 @@ react-remove-scroll@2.5.5:
use-callback-ref "^1.3.0"
use-sidecar "^1.1.2"

react-router-dom@^6.4.3:
react-router-dom@^6.14.1:
version "6.14.1"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.14.1.tgz#0ad7ba7abdf75baa61169d49f096f0494907a36f"
integrity sha512-ssF6M5UkQjHK70fgukCJyjlda0Dgono2QGwqGvuk7D+EDGHdacEN3Yke2LTMjkrpHuFwBfDFsEjGVXBDmL+bWw==
Expand Down

0 comments on commit 3bcff0d

Please sign in to comment.