The goal of reactRouter is to provide a wrapper around React Router (v6).
[!CAUTION] Breaking Change in v.0.1.2 :
reloadDocumentis now FALSE by default inNavLink()andLink(). SetreloadDocument = TRUEonly when target routes contain Shiny server-rendered output likeuiOutput()/renderUI().
Usage
You can easily add URL pages in a Quarto document or R Shiny app like so:
library(reactRouter)
RouterProvider(
Route(
path = "/",
element = div(
NavLink(to = "/", "Main"),
NavLink(to = "/analysis", "Analysis"),
Outlet()
),
Route(index = TRUE, element = "Main content"),
Route(path = "analysis", element = "Analysis content")
)
)Install
#remotes::install_github("lgnbhl/reactRouter") # development version
install.packages("reactRouter")Example
Get started with a showcase example:
# print all examples available: reactRouterExample()
reactRouterExample("dynamic-segment")Read the vignette here for detailed use cases with Quarto and R Shiny.
Choosing a router
The simplest way to add routing is RouterProvider(), which defaults to hash-based routing and works in Shiny apps, static HTML, and Quarto documents:
RouterProvider(
Route(path = "/", element = ..., Route(...))
)
# type = "hash" (default) — URL shows /#/about, bookmarkable
# type = "memory" — URL never changes, great for embedded widgetsLower-level functions (createHashRouter(), createMemoryRouter(), HashRouter(), MemoryRouter(), BrowserRouter()) are also available for more control. See the Choosing a router vignette for details and code examples.
Contribute
Would you like to contribute to the package? Have a look at the current roadmap.
