Routing in $mol is not a separate library — the URL is just another piece of reactive state. Read it, write it, and views react the same way they react to any cell. The back button, deep links, and shareable URLs all come for free.
$mol_state_arg exposes URL parameters as reactive values. Bind one to a property and the address bar becomes your source of truth:1namespace $.$${2export class $my_appextends$.$my_app{3@ $mol_mem4page(next?:string){5return $mol_state_arg.value('page',next)??'home'6}7}8}Reading page() returns the current value; calling page('about') navigates. Anything that reads page() re-renders on change — including the browser's back button, which updates the cell for you.
Combine a routed value with a plain switch to choose what renders. Because views are lazy, the screens you don't show are never built:1@ $mol_mem2body_content(){3switch (this.page()){4case 'about':return[this.About()]5case 'docs':return[this.Docs()]6default:return[this.Home()]7}8}
In view.tree, a link can set URL arguments declaratively — clicking it navigates with no handler:1<= About_link $mol_link2 arg *3 page \about4 sub /<= about_label \About$mol_link also marks itself active (mol_link_current) when its arguments match the current URL, so highlighting the current page needs no extra state.