inst/examples/README.md

reactRouter examples

Each subfolder is a runnable example. Launch any of them with:

reactRouter::reactRouterExample("<name>")
# or
shiny::runApp(system.file("examples", "<name>", package = "reactRouter"))

The recommended entry point is RouterProvider() paired with one of the create*Router() functions. See vignette("routers", package = "reactRouter") for guidance on choosing a router and vignette("introduction", package = "reactRouter") for a tour.

Showcase

| Example | What it shows | |---|---| | basic | Layout route, nested routes, Outlet(), Link(), splat * route | | bslib | reactRouter inside a bslib::page_navbar() | | star-wars-explorer | Larger app: dynamic segments, loaders, errorElement, MUI Material/Charts/DataGrid integration | | shiny.fluent | Multi-page rhino + shiny.fluent dashboard (see folder README) |

Routers

| Example | What it shows | |---|---| | RouterProvider | The recommended entry point | | createHashRouter | Hash-based data router (default choice) | | createMemoryRouter | In-memory data router (wizards, embedded widgets) | | MemoryRouter | Legacy component-based memory router |

Routes & navigation

| Example | What it shows | |---|---| | dynamic-segment | Minimal Route(path = ":id") + useParams() | | useNavigate | Programmatic navigation | | useNavigation | Reading navigation state | | useLocation | Reading the current location | | useParams | Reading route parameters | | useSearchParams / setSearchParams | Reading and updating search params | | useOutlet / useOutletContext | Outlet inspection and parent → child context | | useLinkClickHandler | Custom link components | | useViewTransitionState | View transitions | | useRoutes | Routes-as-data (legacy Routes() API) | | useInRouterContext | Detect whether you are inside a router | | ScrollRestoration | Restore scroll position on navigation |

Data loading & actions

| Example | What it shows | |---|---| | useLoaderData | The basic loader + useLoaderData() pattern | | useLoaderData-api | Loader fetching from a remote API | | Form | Form() GET + loader, POST + action with useActionData() | | useFetcher / useFetchers | Background fetches without navigation | | useSubmit | Programmatic form submission | | useRevalidator | Re-run the current loader on demand | | shouldRevalidate | Skip loader re-runs when data is unchanged | | Await / useAsyncValue / useAsyncError | Deferred / streaming loader data | | useBlocker | Intercept navigation (e.g. unsaved-changes prompt) |

Loader/action helpers

| Example | What it shows | |---|---| | redirect | redirect() from a loader | | redirectDocument | Full-document redirect | | replaceResponse | Replace history entry from a loader | | dataResponse | Loader returning a typed Response | | useRouteError | Catching loader/action errors |

Notes



Try the reactRouter package in your browser

Any scripts or data that you put into this service are public.

reactRouter documentation built on May 10, 2026, 5:07 p.m.