Skip to main content

dimurl

dimurl is the hash router for Dim apps. Routes live in location.hash (#/note/:id) so the same index.html works from GitHub Pages project URLs and plain static hosting — no server rewrite rules. Query flags (?impl=, ?dimuiSrc=, …) stay independent of the route.

Live demo: positive-intentions.github.io/dimurl.

Declarative router (primary API)​

React Router–style custom elements. Nested routes join relative path segments; unmatched routes hide with display: none. Layout routes (those with nested <dimurl-route> children) prefix-match so parent UI stays mounted.

html`
<dimurl-router>
<dimurl-route path="/">
<home-page></home-page>
</dimurl-route>
<dimurl-route path="/folder/:folderId">
<folder-layout></folder-layout>
<dimurl-route path="note/:noteId">
<note-page></note-page>
</dimurl-route>
</dimurl-route>
<dimurl-route path="/note/:noteId">
<note-page></note-page>
</dimurl-route>
</dimurl-router>
`
Element / hookRole
<dimurl-router>Listens to the hash; exposes __dimurl for descendants
<dimurl-route path>Exact match, or prefix match when it has nested routes
<dimurl-link to>push + href="#/…"
useParams / useNavigate / useLocationWalk closest("dimurl-router") (or the host shadow root)

Dim has no React context — hooks resolve the router via the DOM.

Hybrid screens (notes)​

Keep list + editor mounted. Declare URL shapes as empty routes and drive UI from hooks:

html`
<dimurl-router>
<dimurl-route path="/"></dimurl-route>
<dimurl-route path="/folder/:folderId"></dimurl-route>
<dimurl-route path="/note/:noteId"></dimurl-route>
<dimurl-route path="/folder/:folderId/note/:noteId"></dimurl-route>
<dimui-notes-layout .props="${layoutProps}" />
</dimurl-router>
`

useParams() → { folderId, noteId } updates navStack / selection; useNavigate() writes the hash. dimui’s notes shell uses this pattern.


Low-level hash helpers​

Still available for apps that prefer imperative routing:

ModuleRole
dimurl/hashread, match, matchPrefix, compile, joinPaths, push, replace, listen
dimurl/notestoLocation / fromLocation for notes URL shapes
dimurl/hooks/use-hash-location{ path, push, replace, match } without the element tree
BP.module("my/app", ["dimurl/hash", "dimurl/notes"], function (hash, notes) {
hash.listen(function (loc) {
var ui = notes.fromLocation(loc.pathname);
// apply to navStack / selectedId …
});
hash.push(notes.toLocation({ folderFilter: "all", noteId: id }));
});

Override while developing:

?dimurlSrc=http://127.0.0.1:5180/src/

Notes URL model​

Used by dimui notes-shell / dim-boilerplate:

HashMeaning
#/All Notes list
#/folder/:folderIdList for all | pinned | trash | folder id
#/note/:noteIdOpen note (folder defaults to all)
#/folder/:folderId/note/:noteIdOpen note in folder context

In-app back writes the parent hash (does not call history.back()). Browser back/forward still work via hashchange / popstate.


Run / tests​

python3 -m http.server 5180
  • Demo: index.html (<dimurl-router> / <dimurl-route> / <dimurl-link>)
  • Tests: runTests.html (DimTest + coverage; ?impl=js|wasm)