summaryrefslogtreecommitdiff
path: root/frontend/src/components/DeckyRouterState.tsx
diff options
context:
space:
mode:
authorJonas Dellinger <jonas@dellinger.dev>2022-05-30 20:55:51 +0200
committerJonas Dellinger <jonas@dellinger.dev>2022-05-30 20:55:51 +0200
commit8fcaadd8f30182c61809748a324808add56ec1c0 (patch)
tree1e8590a794c7e5b0461a79785e7c059b1a29d91b /frontend/src/components/DeckyRouterState.tsx
parent007860f8f771a7ee62b1c384fbe4f741528a75d5 (diff)
downloaddecky-loader-8fcaadd8f30182c61809748a324808add56ec1c0.tar.gz
decky-loader-8fcaadd8f30182c61809748a324808add56ec1c0.zip
All props of route, expose routerHook
Diffstat (limited to 'frontend/src/components/DeckyRouterState.tsx')
-rw-r--r--frontend/src/components/DeckyRouterState.tsx19
1 files changed, 13 insertions, 6 deletions
diff --git a/frontend/src/components/DeckyRouterState.tsx b/frontend/src/components/DeckyRouterState.tsx
index 3c9a5f9b..72fc5816 100644
--- a/frontend/src/components/DeckyRouterState.tsx
+++ b/frontend/src/components/DeckyRouterState.tsx
@@ -1,11 +1,17 @@
import { ComponentType, FC, createContext, useContext, useEffect, useState } from 'react';
+import { RouteProps } from 'react-router';
+
+export interface RouterEntry {
+ props: Omit<RouteProps, 'path' | 'children'>;
+ component: ComponentType;
+}
interface PublicDeckyRouterState {
- routes: Map<string, ComponentType>;
+ routes: Map<string, RouterEntry>;
}
export class DeckyRouterState {
- private _routes: Map<string, ComponentType> = new Map<string, ComponentType>();
+ private _routes = new Map<string, RouterEntry>();
public eventBus = new EventTarget();
@@ -13,8 +19,8 @@ export class DeckyRouterState {
return { routes: this._routes };
}
- addRoute(path: string, render: ComponentType) {
- this._routes.set(path, render);
+ addRoute(path: string, component: RouterEntry['component'], props: RouterEntry['props'] = {}) {
+ this._routes.set(path, { props, component });
this.notifyUpdate();
}
@@ -29,7 +35,7 @@ export class DeckyRouterState {
}
interface DeckyRouterStateContext extends PublicDeckyRouterState {
- addRoute(path: string, render: ComponentType): void;
+ addRoute(path: string, component: RouterEntry['component'], props: RouterEntry['props']): void;
removeRoute(path: string): void;
}
@@ -56,7 +62,8 @@ export const DeckyRouterStateContextProvider: FC<Props> = ({ children, deckyRout
return () => deckyRouterState.eventBus.removeEventListener('update', onUpdate);
}, []);
- const addRoute = (path: string, render: ComponentType) => deckyRouterState.addRoute(path, render);
+ const addRoute = (path: string, component: RouterEntry['component'], props: RouterEntry['props'] = {}) =>
+ deckyRouterState.addRoute(path, component, props);
const removeRoute = (path: string) => deckyRouterState.removeRoute(path);
return (