inst/examples/bslib/app.R

library(reactRouter)
library(bslib)
library(htmltools)
library(shiny)

Layout <- bslib::page_navbar(
  title = "reactRouter with bslib",
  nav_item(
    reactRouter::NavLink(
      "Home",
      to = "/",
      style = JS(
        '({isActive}) => { return isActive ? {color: "red", textDecoration: "none"} : {}; }'
      )
    )
  ),
  nav_item(
    reactRouter::NavLink(
      "Analysis",
      to = "/analysis",
      style = JS(
        '({isActive}) => { return isActive ? {color: "red", textDecoration: "none"} : {}; }'
      )
    )
  ),
  reactRouter::Outlet()
)

ui <- reactRouter::RouterProvider(
  router = createHashRouter(
    reactRouter::Route(
      path = "/",
      element = Layout,
      reactRouter::Route(
        index = TRUE,
        element = div(
          tags$h3("Home page"),
          p("A basic example of reactRouter with bslib.")
        )
      ),
      reactRouter::Route(
        path = "analysis",
        element = "Content analysis"
      ),
      reactRouter::Route(path = "*", element = "Custom error 404")
    )
  )
)

# htmltools::save_html(ui, "index.html")
htmltools::browsable(ui)

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.