From a03e70eb16a8daf1bf989b978fd277b929db2c1e Mon Sep 17 00:00:00 2001 From: Chizoba Jude Ojini Date: Thu, 29 Oct 2026 10:35:36 +0000 Subject: [PATCH 1/5] Real URLs: path routing instead of hash routes, with old links redirected --- apps/web/index.html | 6 +-- apps/web/public/manifest.webmanifest | 6 +-- apps/web/src/App.tsx | 30 +++++++----- apps/web/src/Home.tsx | 8 ++-- apps/web/src/Landing.tsx | 9 ++-- apps/web/src/Marketing.tsx | 9 ++-- apps/web/src/NotFound.tsx | 17 +++++++ apps/web/src/ToolPage.tsx | 6 ++- apps/web/src/TopBar.tsx | 16 ++++--- apps/web/src/main.tsx | 2 + apps/web/src/pwa.ts | 2 +- apps/web/src/router.tsx | 40 ++++++++++++++++ apps/web/src/routes.test.ts | 47 ++++++++++++++++++ apps/web/src/routes.ts | 71 ++++++++++++++++++++++++++++ apps/web/src/useHash.ts | 12 ----- apps/web/sw.js | 4 +- apps/web/vite.config.ts | 17 ++++--- 17 files changed, 243 insertions(+), 59 deletions(-) create mode 100644 apps/web/src/NotFound.tsx create mode 100644 apps/web/src/router.tsx create mode 100644 apps/web/src/routes.test.ts create mode 100644 apps/web/src/routes.ts delete mode 100644 apps/web/src/useHash.ts diff --git a/apps/web/index.html b/apps/web/index.html index 4ccf142..60dfb40 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -3,9 +3,9 @@ - - - + + + diff --git a/apps/web/public/manifest.webmanifest b/apps/web/public/manifest.webmanifest index b0e771d..b3c7e2f 100644 --- a/apps/web/public/manifest.webmanifest +++ b/apps/web/public/manifest.webmanifest @@ -2,9 +2,9 @@ "name": "Ream: file toolkit", "short_name": "Ream", "description": "A private file toolkit that runs on your computer. Convert, edit and secure PDFs, images and documents without uploading them.", - "id": "./", - "start_url": "./#/tools", - "scope": "./", + "id": "/", + "start_url": "/tools/", + "scope": "/", "display": "standalone", "background_color": "#f2f2f3", "theme_color": "#f2f2f3", diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 1f7621f..051ba1d 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -1,22 +1,30 @@ import { useEffect } from 'react' import { findTool } from '@ream/tools' -import { useHash } from './useHash' +import { usePath } from './router' +import { parseRoute } from './routes' import { Home } from './Home' import { ToolPage } from './ToolPage' import { Landing } from './Landing' import { Legal } from './Legal' +import { NotFound } from './NotFound' export function App() { - const hash = useHash() + const path = usePath() useEffect(() => { scrollTo(0, 0) - }, [hash]) - const id = hash.match(/^#\/tool\/([\w-]+)$/)?.[1] - if (id) return - const cat = hash.match(/^#\/tools\/(pdf|image)$/)?.[1] as 'pdf' | 'image' | undefined - if (cat) return - if (hash === '#/tools') return - if (hash === '#/licence') return - if (hash === '#/notices') return - return + }, [path]) + const route = parseRoute(path) + switch (route.page) { + case 'tool': + return + case 'tools': + return + case 'licence': + case 'notices': + return + case 'notFound': + return + case 'landing': + return + } } diff --git a/apps/web/src/Home.tsx b/apps/web/src/Home.tsx index cd3e98f..6fc7369 100644 --- a/apps/web/src/Home.tsx +++ b/apps/web/src/Home.tsx @@ -4,6 +4,8 @@ import { tools } from '@ream/tools' import { acceptsFile, type Category, type Tool } from '@ream/core' import { setHandoff } from './handoff' import { Breadcrumb, TopBar, filterHref, focus, type Filter } from './TopBar' +import { Link, navigate } from './router' +import { toolPath } from './routes' const ready = tools.filter((t) => t.status === 'ready') const heads: Record = { all: 'All tools', pdf: 'PDF tools', image: 'Image tools' } @@ -31,7 +33,7 @@ export function Home({ cat }: { cat: Filter }) { const open = (t: Tool) => { setHandoff(dropped) - location.hash = `#/tool/${t.id}` + navigate(toolPath(t.id)) } return ( @@ -79,7 +81,7 @@ export function Home({ cat }: { cat: Filter }) {
{s.title && (

- {s.href ? {s.title} : s.title} + {s.href ? {s.title} : s.title}

)}
@@ -113,5 +115,5 @@ export function ToolCard({ tool: t, suggested, dim, onOpen }: { tool: Tool; sugg const box = `blueprint flex h-full w-full flex-col gap-1.5 border p-4 text-left transition-colors duration-150 ${edge}` if (dim) return
{body}
if (onOpen) return - return {body} + return {body} } diff --git a/apps/web/src/Landing.tsx b/apps/web/src/Landing.tsx index 7989c64..2805e08 100644 --- a/apps/web/src/Landing.tsx +++ b/apps/web/src/Landing.tsx @@ -5,6 +5,7 @@ import { Marketing, kicker, primary, secondary, wrap } from './Marketing' import { install, installed, usePwa } from './pwa' import { ToolCard } from './Home' import { filterHref, focus } from './TopBar' +import { Link } from './router' const ready = tools.filter((t) => t.status === 'ready') const pick = (ids: string[]) => ids.map(findTool).filter((t): t is Tool => !!t) @@ -87,7 +88,7 @@ export function Landing() { Convert, edit, compress and secure your files: PDFs, images and Office documents today, with more kinds of file on the way. Every tool runs on your own machine, so your files never reach a server.

- Open the tools + Open the tools
@@ -155,7 +156,7 @@ export function Landing() {

Pick a tool and start. Your files stay with you.

- Open the tools + Open the tools
{groups.map((g, i) => ( @@ -166,9 +167,9 @@ export function Landing() {

{g.title}

{g.blurb}

- + All {ready.filter((t) => t.category === g.cat).length} {g.noun} tools → - +
{g.tools.map((t) => )} diff --git a/apps/web/src/Marketing.tsx b/apps/web/src/Marketing.tsx index 830594d..a5af840 100644 --- a/apps/web/src/Marketing.tsx +++ b/apps/web/src/Marketing.tsx @@ -2,6 +2,7 @@ import type { ReactNode } from 'react' import { Logo } from '@ream/ui' import { ThemeToggle } from './ThemeToggle' import { focus } from './TopBar' +import { Link } from './router' const action = `inline-flex min-h-11 items-center justify-center px-5 font-heading text-[17px] font-semibold tracking-wide transition-colors duration-150 ${focus}` /** the one solid object on a page: an accent fill wearing the corner marks */ @@ -18,9 +19,9 @@ export function Marketing({ children }: { children: ReactNode }) {
- + Ream - + @@ -35,8 +36,8 @@ export function Marketing({ children }: { children: ReactNode }) { © 2026 Chizoba Jude Ojini Version {__APP_VERSION__} - MIT licence - Third-party notices + MIT licence + Third-party notices
diff --git a/apps/web/src/NotFound.tsx b/apps/web/src/NotFound.tsx new file mode 100644 index 0000000..d936c9a --- /dev/null +++ b/apps/web/src/NotFound.tsx @@ -0,0 +1,17 @@ +import { Link } from './router' +import { Marketing, primary, secondary, wrap } from './Marketing' + +export function NotFound() { + return ( + +
+

Page not found

+

There is nothing at this address. Check it for typing mistakes, or pick a tool from the list.

+
+ Open the tools + Home +
+
+
+ ) +} diff --git a/apps/web/src/ToolPage.tsx b/apps/web/src/ToolPage.tsx index 8006b0a..5a746ec 100644 --- a/apps/web/src/ToolPage.tsx +++ b/apps/web/src/ToolPage.tsx @@ -15,6 +15,8 @@ import { SizeEstimate } from './SizeEstimate' import { LazyPdfPage, PdfPage } from './PdfPage' import { usePreview } from './usePreview' import { Breadcrumb, TopBar, focus } from './TopBar' +import { Link, navigate } from './router' +import { toolPath } from './routes' type State = | { kind: 'idle' } @@ -96,7 +98,7 @@ export function ToolPage({ tool }: { tool?: Tool }) {
-

That tool doesn't exist. See all tools.

+

That tool doesn't exist. See all tools.

) @@ -380,7 +382,7 @@ function ResultDialog({ tool, outputs, onClose, onReset }: { tool: Tool; outputs key={t.id} onClick={() => { setHandoff(outputs.map(toFile)) - location.hash = `#/tool/${t.id}` + navigate(toolPath(t.id)) }} className="border border-line px-2.5 py-1 hover:bg-ink/7 focus-visible:outline-2 focus-visible:outline-accent" > diff --git a/apps/web/src/TopBar.tsx b/apps/web/src/TopBar.tsx index a722099..d30befa 100644 --- a/apps/web/src/TopBar.tsx +++ b/apps/web/src/TopBar.tsx @@ -2,11 +2,13 @@ import type { ReactNode } from 'react' import { Logo } from '@ream/ui' import type { Category, Tool } from '@ream/core' import { ThemeToggle } from './ThemeToggle' +import { Link } from './router' +import { categoryPath, toolPath } from './routes' export const focus = 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent' export type Filter = Category | 'all' -export const filterHref = (f: Filter) => (f === 'all' ? '#/tools' : `#/tools/${f}`) +export const filterHref = categoryPath const filterName: Record = { all: 'All tools', pdf: 'PDF', image: 'Images' } /** The app's bar: logo on the left; what the page adds (search) and the theme on the right. */ @@ -14,9 +16,9 @@ export function TopBar({ children }: { children?: ReactNode }) { return (
- + Ream - + {children}
@@ -28,7 +30,7 @@ export function TopBar({ children }: { children?: ReactNode }) { export function Breadcrumb({ cat, tool, className = 'mb-6' }: { cat: Filter; tool?: Tool; className?: string }) { const levels = [{ href: filterHref('all'), label: filterName.all }] if (cat !== 'all') levels.push({ href: filterHref(cat), label: filterName[cat] }) - if (tool) levels.push({ href: `#/tool/${tool.id}`, label: tool.title }) + if (tool) levels.push({ href: toolPath(tool.id), label: tool.title }) return (