Open History to see the last commit
1---
2id: overview
3title: Overview
4---
5β
6React Location is a router for client-side React applications.
7β
8Here are some of its core features at a glance:
9β
10- Asynchronous routing
11 - Promise-based data loaders
12 - Asynchronous route elements
13 - Threshold-based pending route elements
14 - Error boundary route elements
15 - Code-splitting
16 - Post-render async loader APIs (stale-while-revalidate, external cache integration)
17 - Navigation batching with graceful replace/push escalation
18- Deeply integrated Search Params API
19 - JSON-first Search Params
20 - Full `<Link>` and `useNavigate` integration
21 - Full `cmd+click` support
22 - Search Param Immutability w/ Structural Sharing
23 - Batched Updates / Functional Updates
24 - Route Matching
25 - Optional Compression w/ JSURL plugin or your own custom parser/serializer!
26- Hooks for everything: Router, Matches, Route Matching, Preloading
27- Optional route filtering/ranking
28- Optional JSX route definitions
29- Prepackaged simple cache implementation for route loader caching
30- Easy Integration w/ external caches and storage (eg. React Query, Apollo, SWR, RTKQuery)
31β
32## In the beginning...
33β
34React Location got its humble beginnings as a wrapper around the long-winded v6 beta release of [React Router](https://reactrouter.com/). Originally, it solved, skirted, and patched a few of the limitations (essentially a majority of the items on the list of features above). Over time, React Location's feature set outgrew the core capabilities of React Router and required full control over the routing experience to achieve its potential.
35β
36### Why are Search Params so important?
37β
38It's likely that every day, you are faced with the decision of state management in your app. **Where do I put this state?**
39β
40Common answers to this question might include:
41β
42- Server state? Put it in React Query!
43- In-memory app state? Put it in {insert your favorite client-side state manager} (mine is Zustand or Valtio!)
44- Persist on the machine? LocalStorage or SessionStorage, of course.
45β
46**But did you know you're missing one?! What about the URL!**
47β
48All too often I see developers putting state in the wrong places not only because state management is Hardβ’οΈ, but also because their tools are limiting their decisions.
49β
50So, what if storing state in the URL was as easy as storing state in any other first-class state management tool? Would you do it more? Did you know your URLs would then be more sharable, bookmarkable and more consistent across app navigation?
51β
52Much how React Query made handling server-state in your React applications a breeze, React Location similarly **unlocks the power of URL search params**.
53β
54### How does React Location handle Search Params?
55β
56Most applications, even large ones will get away with requiring only a few string-based search query params in the URL, probably something like `?page=3` or `?filter-name=tanner`. The main reason you'll find this **state** inside of the URL is that while it may not fit the hierarchical patterns of the pathname section of the URL, it's still very important to the output of a page. Both the ability to consume these search params and manipulate them without restriction is paramount to your app's developer and user experience. Your users should be able to bookmark/copy-paste/share a link from your app and have consistency with the original state of the page.
57β
58When you begin to store more state in the URL you will inevitably and naturally want to reach for JSON to store it. Storing JSON state in the URL has its own complications involving:
59β
60- Route Matching. Path matching for routes is really only a small part of what a decently designed route tree can do. Being able to match on search params (in its many flavors) should not be considered a "plugin" or afterthought. It should be one of the most integrated and powerful parts of the API.
61- Parsing/Serialization. I'm talking about full-customization here; BYO stringifier/parser.
62- Immutability & Structural Sharing. This one is tricky to explain, but essentially it will save you from the inevitable infinite side-effect rerenders.
63- Compression & Readability. While not out-of-the-box, this is usually desired, so making it simple to get should be as simple as including a library.
64- Low-level declarative APIs to manipulate query state (think `<Link>`, `<Navigate>` and `useNavigate`). This is one where most routers can't or won't go. To do this correctly, you have to buy into your search-param APIs wholesale at the core of the architecture and provide them as a consistent experience through the entire library.
65β
66Let's just say React Location doesn't skimp on search params. It handles all of this out of the box and goes the extra mile!
67β
68### Asynchronous Navigation
69β
70Popularized by frameworks like [Next.js](https://nextjs.org) and now [Remix](https://remix.run), **specifying asynchronous dependencies for routes that can all resolve in parallel before rendering** is quickly becoming table stakes for almost every React Framework out there. It would be nice if Suspense on its own could give us the solution, but without a router to indicate what needs to be pre-loaded, only suspending on render doesn't allow you to avoid waterfall suspense requests.
71β
72This capability of knowing everything that needs to be fetched upfront before navigating is being explored heavily in SSR frameworks, but not in client-side apps. React Location's goal is to provide that same first-class support for specifying arbitrary asynchronous dependencies for your routes while asynchronously suspending navigation rendering until these dependencies are met.
73β
74To do this properly, routing and navigation need to be designed from the ground up to be **fully asynchronous**. The following features in React Location are first-class and native to the entire routing architecture:
75β
76- Scheduling
77- Batching
78- Data Loading
79- Asynchronous Elements
80- Pending states
81- Error handling
82- Preloading
83- Caching
84β
85### So much more!
86β
87Enough overview, there's so much more to do with React Location. Hit that next button and let's get started!