summaryrefslogtreecommitdiff
path: root/frontend/src/lib/router.ts
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-17 14:32:37 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-17 14:32:37 +0800
commit5c0ba37eda80d39e6ceca59bb1d5f4942f858995 (patch)
tree948723f9cedf7ccb0707fa6ee516bd30fe20fd10 /frontend/src/lib/router.ts
downloadstrategy-lab-5c0ba37eda80d39e6ceca59bb1d5f4942f858995.tar.gz
chore: establish Strategy Lab source baseline (development, not release)
Diffstat (limited to 'frontend/src/lib/router.ts')
-rw-r--r--frontend/src/lib/router.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/frontend/src/lib/router.ts b/frontend/src/lib/router.ts
new file mode 100644
index 0000000..3c2631a
--- /dev/null
+++ b/frontend/src/lib/router.ts
@@ -0,0 +1,43 @@
+export interface Route {
+ name: string;
+ params: Record<string, string>;
+ query: URLSearchParams;
+}
+
+export function routeFromHash(): Route {
+ const raw = window.location.hash.replace(/^#/, '') || '/login';
+ const [pathPart, queryPart] = raw.split('?');
+ const segments = pathPart.split('/').filter(Boolean);
+ const query = new URLSearchParams(queryPart ?? '');
+ if (segments[0] === 'login' || segments.length === 0) return { name: 'login', params: {}, query };
+ if (segments[0] === 'register') return { name: 'register', params: {}, query };
+ if (segments[0] === 'reset') return { name: 'reset', params: {}, query };
+ if (segments[0] === 'account') return { name: 'account', params: {}, query };
+ if (segments[0] === 'admin') return { name: 'admin', params: {}, query };
+ if (segments[0] === 'datasets') return { name: 'datasets', params: {}, query };
+ if (segments[0] === 'runs') return { name: 'runs', params: {}, query };
+ if (segments[0] === 'usage') return { name: 'usage', params: {}, query };
+ if (segments[0] === 'projects') {
+ if (!segments[1]) return { name: 'projects', params: {}, query };
+ const id = segments[1];
+ const tab = segments[2] ?? 'data';
+ if (['data', 'strategy', 'backtest', 'results'].includes(tab)) {
+ return { name: `project-${tab}`, params: { id }, query };
+ }
+ return { name: 'project-data', params: { id }, query };
+ }
+ return { name: 'login', params: {}, query };
+}
+
+export function go(path: string) {
+ if (!path.startsWith('#')) path = `#${path.startsWith('/') ? path : `/${path}`}`;
+ window.location.hash = path;
+}
+
+export function replace(path: string) {
+ go(path);
+}
+
+export function projectPath(id: string, tab: 'data' | 'strategy' | 'backtest' | 'results') {
+ return `/projects/${id}/${tab}`;
+}