{"success":true,"name":"put-filter-and-sort-state-in-the-url","description":"A list screen has filters/sort/tabs and refresh or sharing loses them.","category":"ai-brimind","path":"ai-brimind/put-filter-and-sort-state-in-the-url/SKILL.md","file":"SKILL.md","content":"---\nname: put-filter-and-sort-state-in-the-url\ndescription: \"A list screen has filters/sort/tabs and refresh or sharing loses them.\"\n---\n\n# Put Filter and Sort State in the URL\n\n## When to use\nA view's state (active filters, sort order, selected tab, current page) lives only in JS memory, so reload, back-button, or a shared link reverts to defaults.\n\n## Example request\nUser sets four filters, refreshes → everything resets; they rebuild the filters from memory — state lost on reload. A colleague is sent a link to 'the filtered view' → the link opens the default view; the filters weren't in it — unshareable state. Back button after drilling into an item → returns to page 1 unfiltered instead of where they left — navigation state amnesia.\n\n## Instructions\nAct like a developer who treats the URL as the address of a STATE, not just a page — if a view is worth returning to or sharing, its defining state belongs in the URL. Rules: (1) encode view-defining state as query parameters (?status=active&sort=name&page=3) and update them as the user changes filters (history replaceState/pushState, or the router's query API) — choose push vs replace deliberately: push for changes that feel like navigation, replace for rapid refinements, so the back button behaves sanely; (2) on load, INITIALIZE from the URL — parsing params is now an input path, so validate them like any user input (unknown sort field → default, not crash); the URL is typed by hands sometimes; (3) keep it selective: filters, sort, tab, page, search query — yes; transient UI (open dropdown, hover) — no; and defaults should produce CLEAN urls (omit params at default values) rather than tracking noise; (4) the payoff compounds: shareable links, working refresh, honest back-button, and bug reports that include the exact state ('here's the URL where it breaks'). Only proceed once set-filters → refresh → identical view, and a pasted link reproduces the sender's exact screen.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1190\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}