Your URL Is Your State
Scott Hanselman famously said “URLs are UI”
Think about what URLs give us for free:
- Shareability: Send someone a link, and they see exactly what you see
- Bookmarkability: Save a URL, and you’ve saved a moment in time
- Browser history: The back button just works
- Deep linking: Jump directly into a specific application state
Example:
https://prismjs.com/download.html#themes = prism&languages = markup+css+clike+javascript&plugins = line-numbers
URLs are cache keys. Well-designed URLs enable better caching strategies:
If you are not sure if a piece of state belongs in the URL, ask yourself: If someone else clicking this URL, should they see the same state? If so, it belongs in the URL. If not, use a different state management approach.
Jim Nielsen calls these “examples of great URLs”. URLs that explain themselves.